"use strict"; function object(o) { function F() {} F.prototype = o; return new F(); } NDMTRACK = function (o) { var fn = ndm.track[o.trackingEvent] || ndm.track.generic; // flash developer functions var doSomethingWithNielsen = function () { }; // hijack if (o.trackingEvent === "something") { doSomethingWithNielsen(); // you can put a return in here to prevent the call to ndm.track return; } fn(o); } ndm = window.ndm || {}; ndm.track = ndm.track || {}; ndm.track = (function () { var loud = false, sanitise = function (s) { return ((s || "") + "").replace(/['"&!#$%^*:|\/><~;]/gi, ""); }, spec = { }, vendors = { }, listVendors = function () { var a = []; for (p in vendors) { if (vendors.hasOwnProperty(p)) { a.push(p); }} return a; }, error = function (m) { var msg = msg || "Bad argument"; if (loud) { console.error(msg + ". Exiting."); } }, shim = function (o, etype, mask) { var p, j; if (!o) { return error("Null event object passed."); } o.event = etype; // if the vendor is enabled, has a translator with the required method and // is not excluded by a mask then we call the method on the translator - // passing through the original options for (p in vendors) { if (vendors.hasOwnProperty(p) && vendors[p] && vendors[p].isEnabled()) { if (!mask || (mask.test && mask.test(p))) { var fn = (vendors[p].understands(o.event) && vendors[p][o.event]) || vendors[p].error("\"" + o.event + "\" not found in vocabulary") || function() {}; for (j = 0; j != (vendors[p].subscribers[o.event] || []).length; j++) { vendors[p].subscribers[o.event][j].call(); } if (loud) { console.log(p + "." + o.event); } fn(o); } } } }; return { page: function (o, mask) { shim(o, "page", mask); }, slide: function(o, mask) { shim(o, "slide", mask); }, play: function (o, mask) { shim(o, "play", mask); }, pause: function (o, mask) { shim(o, "pause", mask); }, progress: function (o, mask) { shim(o, "progress", mask); }, generic: function (o, mask) { shim(o, "generic", mask); }, custom: function (o, mask) { shim(o, "custom", mask); }, lookup: function (param, vendor) { if (param === "title") { return something; } }, config: { enable: function (name, force) { if (!vendors[name]) { console.log("Vendor identifer \"" + name + "\" does not match /^(" + listVendors().join("|") + ")$/. You will need to supply a translator for this vendor."); return false; } vendors[name].enable(); vendors[name].subscribers = {}; return true; }, subscribe: function (o) { if (o.vendor && vendors[o.vendor]) { if (loud) { console.log(o.vendor + "." + o.event); } vendors[o.vendor].subscribers[o.event] = vendors[o.vendor].subscribers[o.event] || []; vendors[o.vendor].subscribers[o.event].push(o.fn); } else { error("Vendor disabled"); } }, removeDefault: function (o) { if (o.vendor && vendors[o.vendor]) { vendors[o.vendor][o.event] = function () {}; } }, logging: function (on) { loud = on; }, translator: function (name, translator) { vendors[name] = translator; }, vocabulary: function (name, rules) { var that = object(vendors[name]), rule; for (rule in rules) if (rules.hasOwnProperty(rule)) { { that[rule] = rules[rule]; } } this.translator(name, that); }, translatorPrototype: (function () { return { enable: function () { this.enabled = true; }, error: function (msg) { console.error(msg + " for " + this.title + " translator."); }, understands: function (s) { return this.enabled && this.hasOwnProperty(s); }, isEnabled: function () { return !!this.enabled; } }; }()) } }; }()); $(document).ready(function () { ndm.track.config.translator("hbx", function () { var that = object(ndm.track.config.translatorPrototype); that.title = "hbx"; if (!window.hbx) { that.error("Vendor code not found."); return false; } that.page = function (o) { _hbPageView(o.title || ndm.track.lookup("title"), o.value || ndm.track.lookup("hierarchy")); }; that.slide = function (o) { _hbPageView(o.title || hbx.pn, o.value || hbx.mlc); }; that.custom = function (o) { if (o.metric && o.value) { if (/^cv\.c[0-9]{1,2}$/.test(o.metric)) { _hbSet(o.metric, o.value || hbx.pn + "|" + hbx.mlc); _hbSend(); } else { error("Unknown custom metric for HBX"); } } }; that.play = function (o) { // no default console.log("HBX play"); }; return that; }()); ndm.track.config.translator("nielsen", function () { var that = object(ndm.track.config.translatorPrototype); that.title = "nielsen"; if (!window._rsCI || !window._rsDN) { that.error("Vendor code not found."); return false; } that.page = function (o) { // debounce _rsPageEvent(o.title); }; that.slide = function (o) { _rsSlideShowEvent(o.title); }; that.play = function (o) { // no default }; return that; }()); ndm.track.config.translator("google", function () { var that = object(ndm.track.config.translatorPrototype); if (!window._gat) { return false; } that.page = function (o) { _trackPageview(o.url || window.location); }; return that; }()); ndm.track.config.translator("omniture", function () { var that = object(ndm.track.config.translatorPrototype); if (!window.s_code) { return false; } that.page = function (o) { // set some params then dispatch s.tl(); // s.tl(); }; return that; }()); ndm.track.config.translator("coremetrics", function () { var that = object(ndm.track.config.translatorPrototype); if (!window.cm_ClientID) { return false; } that.page = function (o) { // which of these is it? // cmCreateConversionEventTag("Custom two", "2", "Custom", null, "attribute1"); // cmCreatePageElementTag("Scrolled past 800px","Page Scroll",window.location.pathname); }; return that; }()); ndm.track.config.translator("unica", function () { var that = object(ndm.track.config.translatorPrototype); if (!window.NTPT_IMGSRC) { return false; } that.page = function (o) { // ntptEventTag() }; return that; }()); ndm.track.config.logging(false); ndm.track.config.enable("hbx"); });