Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from Financial-Times/add-video-ad-targeting-vid…
Browse files Browse the repository at this point in the history
…eoid-and-brand

Add video ad targeting videoid and brand
  • Loading branch information
Alberto Elias committed Jun 8, 2016
2 parents 159e8bc + fa11a98 commit 3f5aed6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/models/videojs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
});
}

Expand Down Expand Up @@ -162,6 +169,7 @@ class VideoJsPlayer extends Video {
};
}


addVideo() {
let videoIdProperty = 'test-video-' + videoElementIdOrder++;
this.el = document.createElement('video');
Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions test/models/videojs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ describe('VideoJS', () => {
.then(() => {
const checkSdkIsLoaded = checkGoogleVideoSdkLoaded();
checkSdkIsLoaded.should.equal(true);
videojsPlayer.targeting.brand.should.equal('Authers Note');
done();
});
});
Expand Down

0 comments on commit 3f5aed6

Please sign in to comment.