google analytics for jquery mobile 1.2
Greetings,
I'm looking for the definitive answer for using google analytics in jQuery Mobile 1.2. I've tried all of the usual suspects out on the web, but none seem to be working. It would be great if this were posted somewhere within jQuery Mobile content, if it is please point me that direction.
Thanks so much for any help.
Here's what I have that's not working:
<head>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'MO-XXXXXXXX-X']);
_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);
})();
</script>
</head>
<body>
Placed just before closing body tag:
<script type="text/javascript">
$('[data-role=page]').on('pageshow', function (event, ui) {
try {
_gaq.push( ['_trackPageview', event.target.id] );
console.log(event.target.id);
} catch(err) {
}
});
</script>
</body>