Last active
June 17, 2023 11:46
-
-
Save rnagle/9787649 to your computer and use it in GitHub Desktop.
omniture.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Omniture.js is a clean up of Tribune's boilerplate Omniture | |
// code with some added convenience methods for setting vars, | |
// recording page views, etc. | |
// | |
// It sets up a singleton `omniture` object to use for all your | |
// Omniture needs. | |
// | |
// Example use: | |
// | |
// window.omniture.init('saccountgoeshere', { | |
// pageName: 'Chicago Tribune / archives / print - edition.', | |
// server: 'www.chicagotribune.com', | |
// channel: 'Chicago Tribune:archives', | |
// prop38: 'printedition', | |
// prop64: 'mm-dd-yyyy', | |
// hier1: 'Chicago Tribune:archives:print', | |
// hier2: 'archives:print', | |
// hier4: 'archives:print', | |
// eVar20: 'Chicago Tribune', | |
// eVar21: 'printedition' | |
// }); | |
(function() { | |
window.omniture = { | |
s: null, | |
page_views_recorded: 0, | |
metrics_js_src: 'https://secure.chicagotribune.com/hive/javascripts/metrics/s_code_trb.js', | |
init: function(account, parameters) { | |
var self = this, | |
js = document.createElement('script'); | |
js.setAttribute('src', self.metrics_js_src); | |
js.setAttribute('type', 'text/javascript'); | |
js.onload = function() { | |
self.set_vars(parameters); | |
self.set_s_account(account); | |
self.set_prop28(); | |
self.page_view(); | |
self.s = window.s; | |
}; | |
document.getElementsByTagName('head')[0].appendChild(js); | |
return self; | |
}, | |
page_view: function() { | |
var self = this, ret; | |
window.s_code = ret = window.s.t(); | |
self.page_views_recorded += 1; | |
if (ret) | |
self.create_tracking_pixel(); | |
return ret; | |
}, | |
create_tracking_pixel: function() { | |
var temp = document.createElement('div'); | |
temp.innerHTML = window.s_code; | |
document.getElementsByTagName('body')[0].appendChild(temp.children[0]); | |
}, | |
set_var: function(key, value) { | |
window.s[key] = value; | |
}, | |
set_vars: function(parameters) { | |
var self = this; | |
for (var key in parameters) { self.set_var(key, parameters[key]); } | |
}, | |
set_s_account: function(value) { | |
window.s_account = value; | |
}, | |
ssorid: function(mid){ | |
var m = mid; | |
if (null === m || '' === m) { return false; } | |
var metricArr = m.split('-').reverse(); | |
var retArr = []; | |
var _metricsOrder = [0,5,3,2,4,4,6,2,7,1]; | |
for(var i=_metricsOrder.length;i--;){ | |
retArr[_metricsOrder[i]] = metricArr[i]; | |
} | |
return retArr.slice(0,3).join('-'); | |
}, | |
set_prop28: function() { | |
if(!!window.registration){ | |
var registration_username_c_unm = $.cookies.get('c_unm'); | |
var registration_masterid_c_mid = this.ssorid($.cookies.get('metrics_id')); | |
if (registration_username_c_unm !== null && registration_masterid_c_mid) | |
s.prop28=ssorid($.cookies.get('metrics_id')); | |
} | |
if (s.prop28 === null) | |
s.prop28 = ""; | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment