Skip to content

Instantly share code, notes, and snippets.

@herdianf
Created June 8, 2017 07:00
Show Gist options
  • Save herdianf/4a483bec57e3036d22cb825204483608 to your computer and use it in GitHub Desktop.
Save herdianf/4a483bec57e3036d22cb825204483608 to your computer and use it in GitHub Desktop.
cnaagent.js
window.initVideoTracking = function(player) {
window.gfkSsaConf = {
"media": "",
"url": "//sg-config.sensic.net/sg1-ssa-w.js"
};
(function(w, d, c, s, id) {
if (d.getElementById(id)) {
return;
}
w["gfk"] = w["gfk"] || {};
w["gfk"]["ssa"] = w["gfk"]["ssa"] || {};
w["gfk"]["ssa"].agents = w["gfk"]["ssa"].agents || [];
w["gfk"]["ssa"].getAgent = function() {
var agent = { "queue": [], "a": arguments };
agent.notifyLoaded = function() {
agent.queue.push({
"f": "notifyLoaded",
"t": new Date().getTime(),
"a": arguments
});
};
agent.notifyPlay = function() {
agent.queue.push({
"f": "notifyPlay",
"t": new Date().getTime(),
"a": arguments
});
};
agent.notifyIdle = function() {
agent.queue.push({
"f": "notifyIdle",
"t": new Date().getTime(),
"a": arguments
});
};
agent.notifySkipped = function() {
agent.queue.push({
"f": "notifySkipped",
"t": new Date().getTime(),
"a": arguments
});
};
w["gfk"]["ssa"].agents.push(agent);
return agent;
};
var tag = d.createElement(s);
var el = d.getElementsByTagName(s)[0];
tag.id = id;
tag.async = true;
tag.type = 'text/javascript';
tag.src = c.url;
el.parentNode.insertBefore(tag, el);
})(window, document, gfkSsaConf, 'script', 'gfkSsa');
window.cnaAgent = gfk.ssa.getAgent("ChannelNewsAsiaWeb");
function getContentByMetaTagName(c) {
for (var b = document.getElementsByTagName("meta"), a = 0; a < b.length; a++) {
if (c == b[a].name || c == b[a].getAttribute("property")) {
return b[a].content;
}
}
return false;
}
var rootUrlSgement = "news",
currentTime = 0,
title = typeof(mcDataLayer) != 'undefined' ? mcDataLayer.contentname : getContentByMetaTagName('og:title'),
playerName = rootUrlSgement + '__OoyalaPlayer';
this.options.videoTitle = rootUrlSgement + '_' + this.options.title;
this.options.duration = parseInt(this.options.duration);
if (isNaN(this.options.duration) || this.options.duration == 0) {
this.options.duration = 'null';
} else {
this.options.duration = Math.floor(this.options.duration > 1000 ? this.options.duration / 1000 : this.options.duration);
}
this.options.cnaGfK = {
"contentId": this.options.contentId,
"cp": {
"cp1": this.options.cp1,
"cp2": this.options.assetId,
"cp3": this.options.title,
"cp4": this.options.duration,
"cp5": "null",
"cp6": this.options.episodeTitle || 'null',
"cp7": "null",
"cp8": this.options.duration,
"cp9": this.options.pubDate ? this.options.pubDate + "+0800" : null,
"cp10": this.options.webExclusive,
"cp11": "0",
"cp12": location.href,
"cp13": "en",
"cp14": this.options.categoryTitle,
"cp15": "Channel NewsAsia",
"cp16": "null",
"cp17": "null"
}
};
player.subscribe('*', 'play', function(obj) {
var that = obj,
cnaGfK = that.options.cnaGfK,
videoTitle = that.options.videoTitle,
isInitMediaTracking = false,
duration = that.options.duration,
stopped = true;
return function(eventName) {
if (eventName == OO.EVENTS.PLAYHEAD_TIME_CHANGED) {
currentTime = arguments[1];
}
if (eventName == OO.EVENTS.PLAYBACK_READY) {
cnaAgent.notifyLoaded(cnaGfK.contentId, cnaGfK.cp);
} else if (eventName == OO.EVENTS.PLAYING) {
cnaAgent.notifyPlay();
} else if (eventName == "willPlaySingleAd") {
cnaAgent.notifyIdle();
} else if (eventName == OO.EVENTS.BUFFERING) {
cnaAgent.notifyIdle();
} else if (eventName == OO.EVENTS.PAUSED) {
cnaAgent.notifyIdle();
} else if (eventName == OO.EVENTS.PLAYED) {
cnaAgent.notifyIdle();
}
}
}(this));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment