diff --git a/src/models/videojs.js b/src/models/videojs.js index 29bf1d4..de980db 100644 --- a/src/models/videojs.js +++ b/src/models/videojs.js @@ -112,6 +112,12 @@ class VideoJsPlayer extends Video { advertising = opts && opts['advertising'] ? true : false; ensureAllScriptsAreLoaded(); super(el, opts); + this.targeting = { + site: '/5887/ft.com', + position: 'video', + sizes: '592x333|400x225', + videoId: this.id + }; } getData() { @@ -128,6 +134,7 @@ class VideoJsPlayer extends Video { this.brightcoveData = data; this.posterImage = updatePosterUrl(data.videoStillURL, this.opts.optimumWidth); this.rendition = getAppropriateRendition(data.renditions); + this.targeting.brand = this.getVideoBrand(); }); } @@ -162,6 +169,7 @@ class VideoJsPlayer extends Video { }; } + addVideo() { let videoIdProperty = 'test-video-' + videoElementIdOrder++; this.el = document.createElement('video'); @@ -181,10 +189,36 @@ class VideoJsPlayer extends Video { }); } + getVideoBrand() { + if(!this.brightcoveData.tags || this.brightcoveData.tags.length === 0) { + return false; + } else { + let filtered = this.brightcoveData.tags.filter(val => val.toLowerCase().indexOf('brand:') !== -1); + if(filtered.length > 0) { + try { + // when we target the value in the ad server, we only want to target actual brand name, so we strip out "brand:" part of the string + return filtered.pop().substring(6); + } + catch (e) { + return false; + } + } else { + return false; + } + } + } + advertising(player, videoIdProperty) { + // ad server request call that contains ad server details such as: site(iu), sizes(sz), position(pos), video id(ttid) and branding(brand) if it is available + // these key values are then used on ad server to target pre roll advertising + let advertisingUrl = `http://pubads.g.doubleclick.net/gampad/ads?env=vp&gdfp_req=1&impl=s&output=xml_vast2&iu=${this.targeting.site}&sz=${this.targeting.sizes}&unviewed_position_start=1&scp=pos%3D${this.targeting.position}&ttid=${this.targeting.videoId}`; + if(this.targeting.brand) { + advertisingUrl += `&brand=${encodeURIComponent(this.targeting.brand)}`; + } + player.ima({ id: videoIdProperty, - adTagUrl: 'http://pubads.g.doubleclick.net/gampad/ads?env=vp&gdfp_req=1&impl=s&output=xml_vast2&iu=/5887/ft.com&sz=592x333|400x225&unviewed_position_start=1&scp=pos%3Dvideo' + adTagUrl: advertisingUrl }); player.ima.requestAds(); } diff --git a/test/models/videojs.test.js b/test/models/videojs.test.js index 5154080..29d8822 100644 --- a/test/models/videojs.test.js +++ b/test/models/videojs.test.js @@ -173,6 +173,7 @@ describe('VideoJS', () => { .then(() => { const checkSdkIsLoaded = checkGoogleVideoSdkLoaded(); checkSdkIsLoaded.should.equal(true); + videojsPlayer.targeting.brand.should.equal('Authers Note'); done(); }); });