Javascript API

Setup and pass page level KV pairs for Google Ad Manager

You can pass page level custom KV data into Google Ad Manager with the following API:

window.dataLayer = window.dataLayer || []
dataLayer.push({
  event: 'gam.targeting',
  KEY_NAME: VALUES,
})

For example:

window.dataLayer = window.dataLayer || []
dataLayer.push({
  event: 'gam.targeting',
  keywords: ['English Premier League'],
  pageType: 'article',
})

Disable advertising on a specific URL:

You can use the following API to disable the advertising on a URL:

window.dataLayer = window.dataLayer || []
dataLayer.push({
  event: 'bs.targeting',
  articleType: 'noads',
})

Teardown and bootstrap the ad engine with API

if (window.BIDDINGSTACK) {
  window.BIDDINGSTACK.api.teardown()
  window.BIDDINGSTACK.api.bootstrap()
}

Discover new ad slots on the page

If the website utilises infinite scrolling, there could be new ad slots added to the page dynamically. You have to call the following API after content is rendered on the page, and then the engine will fill ads into the new ad slots.

if (window.BIDDINGSTACK) {
  window.BIDDINGSTACK.api.discoverSlots()
}

Updating and Persisting Key-Value Targeting for Google Ad Manager

You can store custom key-value (KV) data in the user's browser and pass it to Google Ad Manager using the following API:

if (window.BIDDINGSTACK) {
  window.BIDDINGSTACK.api.setGAMTargeting(key, value)
}

For example:

if (window.BIDDINGSTACK) {
  window.BIDDINGSTACK.api.setGAMTargeting("audience_seg", ["Sports", "Shopping"])
}

// or

if (window.BIDDINGSTACK) {
  window.BIDDINGSTACK.api.setGAMTargeting("audience_seg", "Sports")
}

// or remove the KV

if (window.BIDDINGSTACK) {
  window.BIDDINGSTACK.api.setGAMTargeting("audience_seg", null)
}

In this example:

  • Replace "audience_seg" with your desired key.
  • ["Sports", "Shopping"] represents an array of values associated with the key.