Reputation: 6462
jQueryMobile loads its first page as every site does. The usual Google Analytics integration works - the request ist tracked. But following pages are loaded asynchronously and user clicks are not tracked.
How to integrate Google Analytics into a jQueryMobile website, so that all page clicks are tracked?
Upvotes: 12
Views: 7448
Reputation: 2534
For those having problems with Phonegap and google analytics :
Google code uses cookies and it doesn't work with file:// urls wich is what Phonegap uses. The Pokki team made a good implementation that uses localStorage in place of cookies. I made a fork on github to remove the need of pokki, so here is a solution that works with phonegap as a standalone library
https://github.com/ggendre/GALocalStorage
hope this will help someone else :)
Upvotes: 4
Reputation: 2522
Jon Gales has written a great article on this.
http://www.jongales.com/blog/2011/01/10/google-analytics-and-jquery-mobile/
Here's the code he recommends using:
$('[data-role=page]').live('pageshow', function (event, ui) {
try {
_gaq.push(['_setAccount', 'YOUR_GA_ID']);
hash = location.hash;
if (hash) {
_gaq.push(['_trackPageview', hash.substr(1)]);
} else {
_gaq.push(['_trackPageview']);
}
} catch(err) {
}
});
Update
Since live
is now deprecated you should use the on
event instead, if you´re using jQuery 1.7+. http://api.jquery.com/on/
Upvotes: 15
Reputation: 9498
http://code.google.com/apis/analytics/docs/mobile/overview.html http://analytics.blogspot.com/2009/10/google-analytics-now-more-powerful.html
These are references, please read for your knowladge.
Upvotes: 0