Skip to content

SpotX tag generator for plyr

Ferdi edited this page Jun 20, 2017 · 2 revisions
var player = plyr.setup();
plyrAds.setup(player, {
    adTagUrl: _getAdsUrl(player)
});

function _getAdsUrl(player) {
    var tag = 'https://search.spotxchange.com/vast/2.0/85394?VPAID=JS' +
              '&content_page_url=__content_page_url__' +
              '&cb=__random-number__' +
              '&player_width=__player-width__' +
              '&player_height=__player-height__' +
              '&media_transcoding=low';
    try {
      player.forEach(function(instance) {
        var playerstyle = (typeof (window.getComputedStyle) !== 'undefined') ? 
window.getComputedStyle(instance.getContainer(), null) : instance.getContainer().currentStyle;
        tag = tag.replace('__content_page_url__', escape(document.location.href));
        tag = tag.replace('__player-width__', Math.max(parseInt(playerstyle.width, 10) || 0, 100));
        tag = tag.replace('__player-height__', Math.max(parseInt(playerstyle.height, 10) || 0, 100));
        tag = tag.replace('__random-number__', Math.round(Math.random() * 100000) );
      });
    } finally {
      return tag;
    }
  }
Clone this wiki locally