In this article
How to send cohorts to YouTube player For Publishers for targeting.
You can use Permutive cohorts for targeting YouTube for Publishers on pages where Permutive is already deployed. All cohorts that have the Google Ad Manager activation turned on in Permutive will be targetable on Youtube For Publishers too, if you follow the below implementation steps.
Implementation
Note: For this to work, you will need to have the Google Ad Manager integration set up.
When embedding your video (YouTube's documentation can be found here), you can specify an embedConfig
object. In it, you are able to pass in custom key-value pairs for targeting using the object adsConfig.adTagParameters.cust_params
.
Note: cust_params
must be URI-encoded.
Below is an example of how this can be achieved, ( segs
are Permutive cohort IDs).
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'XDgC4FMftpg',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
},
embedConfig: '{"adsConfig": {"adTagParameters": {"cust_params": ' + encodeURIComponent(segs) + '}}}'
});
}
In order to retrieve Permutive cohort IDs dynamically, you can check the local storage variable _pdfps
, which is updated as soon as Permutive has added a user to a cohort on the page.
Note: If the video is loaded before Permutive has run on the page, the cohorts retrieved from localStorage may not yet be updated from the previous Pageview.
Below is an example of how Permutive cohorts can be retrieved in a variable called segs
.
var segs
try {
segs = JSON.parse(window.localStorage._pdfps || '[]').slice(0,250).toString()
} catch (e) {
segs = ''
}
After following these steps, your Player configuration could look like the following:
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'XDgC4FMftpg',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
},
embedConfig: '{"adsConfig":{"adTagParameters":{"cust_params":"permutive%3D11111%2C22222"}}}'
});
}
If you have any questions, please contact customer support by emailing support@permutive.com or chat to the Customer Operations Team via the LiveChat icon in the bottom right corner of your screen.
Comments
0 comments
Article is closed for comments.