Sending Segments to YouTube Player

In this article

How to send segments to YouTube player For Publishers for targeting.

You can use Permutive segments for targeting YouTube for Publishers on pages where Permutive is already deployed. All segments 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 segment 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 segment IDs dynamically, you can check the local storage variable _pdfps, which is updated as soon as Permutive has segmented the user on the page.

Note: If the video is loaded before Permutive has run on the page, the segments retrieved from localStorage may not yet be updated from the previous Pageview.

Below is an example of how Permutive segments 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.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request