Freestar's wrapper includes several methods publishers can use to trigger events.
Overview
There may be times when you want an ad to trigger after some event. For example, a user...
- Finishes a game
- Closes or opens a pop-up
- Scrolls to show more content (i.e., infinite scroll pages)
- Loads a new page in an SPA environment
newAdSlots
Use the newAdSlots method to call an ad. It accepts three arguments, element (required), channel (optional), and targeting (optional). Pass the method tofreestar.queue.
JavaScript
freestar.queue.push(function() {
freestar.newAdSlots(elements, channel = null, targeting = {})
});
Element
element requires an object with two properties, placementName and slotID.
JavaScript
freestar.queue.push(function() {
freestar.newAdSlots({
placementName: 'myplacement_300x250_InContent',
slotId: 'my-element-id'
})
});
Channel
Optional. Please see the Channel Variable page for more information.
JavaScript
freestar.queue.push(function() {
freestar.newAdSlots({
placementName: 'myplacement_300x250_InContent',
slotId: 'my-element-id'
},
channel = 'homepage')
});
Key-Value Pairs
Optional. For more information, please see the Key-Value Pair Targeting page.
JavaScript
freestar.queue.push(function() {
freestar.newAdSlots({
placementName: 'myplacement_300x250_InContent',
slotId: 'my-element-id',
targeting: {
key1: value1,
key2: value2
}
})
});
deleteAdSlots
Use the deleteAdSlots method to destroy an ad slot. The method accepts a single slotId or an array of slot IDs. Passing nothing will delete all ad slots on the page.
JavaScript
// Delete one of the ad slots on the page based on the slotId
freestar.queue.push(function() {
freestar.deleteAdSlots('ad_300x250_1');
});
// Delete two of the slots. Note to pass the strings in an Array
freestar.queue.push(function() {
freestar.deleteAdSlots(['ad_728x90_1', 'ad_300x250_2']);
});
// Delete all ad slots on a page
freestar.queue.push(function() {
freestar.deleteAdSlots();
});
📘 When an event occurs without a full page refresh, it is recommended to destroy the ad using
deleteAdSlots.
Refresh
Optional. Use the refresh method to refresh ads on the page. This method accepts a slotId (optional), either as a string (individual) or an array (multiple). Passing nothing refreshes all ad slots on the page. Pass the method tofreestar.queue.
By default, Freestar's ad units refresh every 30 seconds. Please consult with support before implementing the
refreshmethod by submitting a request here.