Skip to content

Instantly share code, notes, and snippets.

@ryanbmarx
Created August 14, 2018 16:43
Show Gist options
  • Save ryanbmarx/281522c21173bc4e64a7c743a4f99b25 to your computer and use it in GitHub Desktop.
Save ryanbmarx/281522c21173bc4e64a7c743a4f99b25 to your computer and use it in GitHub Desktop.
<script type='text/javascript'>
// Start by looking for a url variable. This is how we force one header or
// the other to test them. If there is a url variable, assign it to the rando
// variable. Otherwise generate a random number.
var pageUrl = window.location.href.split(/[?&]/),
rando;
if (pageUrl.length > 1){
for (let i=1; i< pageUrl.length; i++){
if (pageUrl[i].indexOf('header') > -1){
rando = pageUrl[i].split('=')[1];
}
}
} else {
rando = Math.random();
}
var eVar33,
chartbeatPath,
header = document.querySelector('#header .header__container');
if (rando >= .5){
// If the random number (0-1) is greater than .5, show the video header
header.innerHTML = document.getElementById('headerVideo').innerHTML;
// Assign values to our analytic variables
eVar33 = "Video header";
chartbeatPath = "?header=1";
// Add a helper class to our header
header.parentNode.classList.add('header--video');
} else {
// If the random number (0-1) is less than .5, show the static header
header.innerHTML = document.getElementById('headerPlain').innerHTML;
eVar33 = "Plain header";
chartbeatPath = "?header=0";
header.parentNode.classList.add('header--static');
}
// With out header selected, now configure/init Omniture with the proper values
((((window.trb || (window.trb = {})).data || (trb.data = {})).metrics || (trb.data.metrics = {})).thirdparty = {
pageName: 'ct:apps:news:{{ name }}:articleproject.',
channel: 'news',
server: 'graphics.chicagotribune.com',
hier1: 'chicagotribune:news',
hier2: 'news',
prop1: 'D=pageName',
prop2: 'news',
prop38: 'articleproject',
prop57: 'D=c38',
prop59: '',
eVar20: 'chicagotribune',
eVar21: 'D=c38',
eVar33: eVar33,
eVar34: 'D=ch',
eVar35: 'D=pageName',
events:''
});
// Use the path attribute to differentiate between the two headers
var _sf_async_config = _sf_async_config || {};
var pageTitle = `{{ title }}`;
_sf_async_config.uid = 25745
_sf_async_config.domain = 'chicagotribune.com';
_sf_async_config.useCanonical = false;
_sf_async_config.sections = 'Watchdog, Investigation, Better Housing';
_sf_async_config.authors = 'Joe Mahr';
_sf_async_config.title = pageTitle;
_sf_async_config.path = `/chicago-charity-housing-violations${chartbeatPath}`;
(function() {
function loadChartbeat() {
var e = document.createElement('script');
e.setAttribute('language', 'javascript');
e.setAttribute('type', 'text/javascript');
e.setAttribute('src', '//static.chartbeat.com/js/chartbeat.js');
document.body.appendChild(e);
}
var oldonload = window.onload;
window.onload = (typeof window.onload != 'function') ?
loadChartbeat : function() {
oldonload();
loadChartbeat();
};
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment