Custom Code
Last edited date: 2024/05/23
You can use Yieldbird Platform tag to serve any custom snippet of JavaScript code you want using the custom code feature. The code can be executed before Yieldbird configuration or after it.
All it does is it takes the entire code snippet you add and serve it through Yieldbird Tag before serving the entire Yieldbird’s configuration or after serving it
Use cases are literally infinite. A common one is to connect with a 3rd party tool's script.
- Size limitations - you should not use the custom code as a private code storage. The main purpose of this feature is to test some setup changes on your side, apply changes that cannot be done through Yieldbird's platform user interface.
- Make sure to manage your code. If you test anything using Custom Code, make sure to clean it up after the test is finished.
- Test your code first. Do not apply code to Custom Code without any testing. Make sure it is free of semantic or functional errors (the feature has a built-in semantics checker to make it easier).
- Before implementing the custom code at scale, we recommend that you set up a "staging environment" with a specific URL. Additionally, you can test it on a portion of your traffic.
- You must be absolutely sure that the source of your code is secure. Applying code without a background check may lead to various dangerous scenarios.
Examples
An example of custom code before - attaching event listeners to the Google Publisher Tag (GPT):
// Custom code before
(function () {
window.googletag.cmd.push(function () {
window.googletag.pubads().addEventListener('impressionViewable', function (event) {
console.log('Impression viewable: ' + event.slot.getSlotElement())
})
})
})();
Attaching custom script after Yieldbird config execution:
// Custom code after
(function () {
const customScript = document.createElement('script')
const useSSL = document.location.protocol === 'https:'
const node = document.getElementsByTagName('script')[0]
customScript.async = true
customScript.type = 'text/javascript'
customScript.src = `${useSSL ? 'https:' : 'http:'}//mycustomjsfile.js`
node.parentNode.insertBefore(customScript, node)
// if you need to make sure that this script is fired after the wrapper execution, you can call in the Yieldbird queue:
window.Yieldbird.cmd.push(function () {
const customScript = document.createElement('script')
const useSSL = document.location.protocol === 'https:'
const node = document.getElementsByTagName('script')[0]
customScript.async = true
customScript.type = 'text/javascript'
customScript.src = `${useSSL ? 'https:' : 'http:'}//mycustomjsfile.js`
node.parentNode.insertBefore(customScript, node)
}); */
})();
Limitations
Custom code cannot be used to implement Prebid modules (e.g., Bidder or Analytics Adapters). To use a Prebid module, it must be available in the Prebid Stack.
On this page: