Last active
December 22, 2015 00:28
-
-
Save bvassilis/6389408 to your computer and use it in GitHub Desktop.
jquerymobile import multi google analytics tracking code
This file contains 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
var _gaq = _gaq || []; | |
(function() { | |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
function domainPageTrackingCode (trackingId, domain) { | |
try { | |
_gaq.push(['_setAccount', trackingId]); | |
_gaq.push(['_setDomainName', domain]); | |
if ($.mobile.activePage.attr("data-url")) { | |
_gaq.push(['_trackPageview', $.mobile.activePage.attr("data-url")]); | |
} else { | |
_gaq.push(['_trackPageview']); | |
} | |
} catch(err) { | |
console.log(err); | |
} | |
} | |
$('[data-role=page]').on('pageshow', function (event, ui) { | |
domainPageTrackingCode('UA-XXXXXXXX-1', 'DOMAIN1'); | |
domainPageTrackingCode('UA-XXXXXXXX-2', 'DOMAIN1'); | |
domainPageTrackingCode('UA-XXXXXXXX-3', 'DOMAIN2'); | |
// .... continue writing other similar google analytics domain tracking code | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment