Created
January 17, 2013 23:13
-
-
Save dalethedeveloper/4560788 to your computer and use it in GitHub Desktop.
More robust Google Analytics tracking for Zoey (http://blog.angeloff.name/zoey/), in particular treating single-page <article> tags as pageviews. Tucking the view under the /mobile/[panel id] for simpler segment/search.
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 || []; | |
_gaq.push(['_setAccount', 'UA-22762790-1']); | |
// DELAY _gaq.push(['_trackPageview']); | |
(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); | |
})(); | |
// Delegate these to events in Zoey | |
$(document).ready(function(){ | |
$(document).delegate('article','pageshow',function(){ | |
if (typeof _gaq !== "undefined" && _gaq !== null) | |
_gaq.push(['_trackPageview', '/mobile/' + this.id ]); | |
}); | |
$(document).delegate('a[rel="external"]','click',function(event){ | |
var href = $(this).attr('href'); | |
if (typeof _gaq !== "undefined" && _gaq !== null) | |
_gaq.push(['_trackPageview', '/mobile/outbound/' + href]); | |
}); | |
if( window.location.hash && $(window.location.hash).length == 0 ) | |
window.location.hash = '#home'; | |
// Delay Analytics until now, track initial view (rest will delegate to 'pageshow') | |
if (typeof _gaq !== "undefined" && _gaq !== null) | |
_gaq.push(['_trackPageview', '/mobile/' + ( window.location.hash.length ? window.location.hash.substr(1) : '')]); | |
// Pretty loading graph | |
$(document).delegate('article','pagebeforehide',function(){ Zoey.loading(true); }); | |
$(document).delegate('article','pageshow',function(){ Zoey.loading(false); }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment