Created
August 1, 2012 15:42
-
-
Save tomfuertes/3227961 to your computer and use it in GitHub Desktop.
Base Tag Restructuring Pending jQuery Load
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
| (function (window, document, undefined) { | |
| // Load a script and fire callback | |
| function loadScript(url, callback) { | |
| var cdn = document.createElement('script'); | |
| cdn.type = 'text/javascript'; | |
| cdn.async = true; | |
| cdn.src = url; | |
| cdn.onload = function () { | |
| if (!cdn.onloadDone) { | |
| cdn.onloadDone = true; | |
| callback(window.jQuery.noConflict(true)); | |
| delete cdn.onload; | |
| delete cdn.onreadystatechange; | |
| } | |
| }; | |
| cdn.onreadystatechange = function () { | |
| if (("loaded" === cdn.readyState || "complete" === cdn.readyState) && !cdn.onloadDone) { | |
| cdn.onloadDone = true; | |
| callback(window.jQuery.noConflict(true)); | |
| delete cdn.onload; | |
| delete cdn.onreadystatechange; | |
| } | |
| } | |
| var s = document.getElementsByTagName('script')[0]; | |
| s.parentNode.insertBefore(cdn, s); | |
| } | |
| function webAnalyticsBaseTag(jQuery) { | |
| if (typeof jQuery == "undefined") { | |
| loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', webAnalyticsBaseTag) | |
| return; | |
| } | |
| (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); | |
| })(); | |
| 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 ... */ | |
| 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]]); | |
| }); | |
| } | |
| webAnalyticsBaseTag(window.jQuery); | |
| })(this, this.document); |
Author
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initial Import: https://gist.github.com/3227961/7bf5a65e3f5ba02bb26f82a90bc8ab36b630cff7