I've seen lots of posts that explain how to integrate Google analytics with your JQM site, but it doesn't seem to be working for me. I'm using JQM version 1.2 and have an external javascript file containing this code:
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-12345678-9']);
(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); })();
$('[data-role=page]').live('pageshow', function (event, ui) { try { hash = location.hash; if (hash && hash.length > 1) { _gaq.push(['_trackPageview', hash.substr(1)]); } else { _gaq.push(['_trackPageview']); } } catch(err) { } });
Can you spot why this isn't working? Do I need to load the code inline on each page rather than have it in an external file?