Skip to content

Instantly share code, notes, and snippets.

@tomfuertes
Created August 2, 2012 14:06
Show Gist options
  • Select an option

  • Save tomfuertes/3237334 to your computer and use it in GitHub Desktop.

Select an option

Save tomfuertes/3237334 to your computer and use it in GitHub Desktop.
Base Tag Restructuring Pending Bootstrapper.bindDomParsed
(function () {
var cdn = document.createElement('script');
cdn.type = 'text/javascript';
cdn.async = true;
cdn.src = '//sub.domain.com/shared/bootstrap/0.8.0.2/js/libs/gas-utils.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(cdn, s);
})();
(function () {
webPropertyId = [];
domain = [];
siteId = [];
webPropertyId[0] = 'UA-XXXXXX-1';
webPropertyId[1] = 'UA-XXXXXX-1';
domain[0] = 'domain.com';
domain[1] = 'example.com';
siteId[0] = '';
siteId[1] = '';
window.analyticsdatalayer = window.analyticsdatalayer || {};
window._gas = window._gas || [];
var j = 0;
var accountSet = false;
for (i = 0; i < domain.length; i++) {
if ((siteId[i] != '') && (document.getElementsByTagName('html')[0].id == siteId[i])) {
_gas.push(['_setAccount', webPropertyId[i]]);
accountSet = true;
}
_gas.push(['_setDomainName', domain[i]]);
}
if (!accountSet) {
for (i = 0; i < domain.length; i++) {
if ((webPropertyId[i] != '') && (location.hostname.indexOf(domain[i]) != -1)) {
_gas.push(['_setAccount', webPropertyId[i]]);
}
}
}
for (i = 0; i < domain.length; i++) {
if (location.hostname.indexOf(domain[i]) != -1) {
j = i;
}
}
/* ... SNIP ... */
function jqDependants() {
if ((jQuery('meta[name="contrk"]').attr('content')) !== undefined) {
canonical = (jQuery('meta[name="contrk"]').attr('content'));
_gas.push(['_setCustomVar', 21, 'Canonical', canonical, 3]);
}
_gas.push(['_trackPageview']);
var isOverGoogleAd = false;
jQuery('iframe[src*="ad.doubleclick.net"]').mouseover(function () {
isOverGoogleAd = true;
}).mouseout(function () {
isOverGoogleAd = false;
});
jQuery(window).blur(function () {
if (isOverGoogleAd) {
_gas.push(['_setCustomVar', 18, 'AdSense Clicked', 'clicked', 2]);
_gas.push(['_trackEvent', 'AdSense', 'clicked', analyticsdatalayer.pagename]);
}
});
jQuery('a[href*="icid"]').click(function () {
regex = new RegExp('[?&]icid=([^&]*)');
icid = jQuery(this).attr('href').match(regex);
_gas.push(['_setCustomVar', 19, 'Internal Promotion', icid[1], 2]);
_gas.push(['_trackEvent', 'Internal Promotion', 'clicked', icid[1]]);
});
}
if (typeof jQuery == "undefined") {
Bootstrapper.bindDomParsed(function () {
jqDependants();
});
} else {
jqDependants();
}
})();​
@tomfuertes
Copy link
Copy Markdown
Author

@tomfuertes
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment