The Google Analytics ga.js script is designed to work with cookies, but as your Sencha Touch app is probably running through something like PhoneGap, it is being accessed using the file:// protocol, so no cookies – which means that if you simply include the normal Google Analytics script, nothing will happen.
The heart of the ga.js file is loading the __utm.gif image, with a number of parameters that Google then uses to generate your stats. Most websites just track page loads, but again, with a Sencha Touch (or any javascript-based app running locally) there is generally only one page load.
The best way to track usage with Google Analytics in a javascript-based app running locally – that I have found – is to use “events”. You must trigger these events for things that you want to track (e.g., in Sencha Touch you probably want to track the “cardswitch” event on your viewport). You can find more info about events with Google Analytics at http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
It’s important to understand how “events” work with Google Analytics, so please read that page… now that you have read it, you need to know that you won’t be using the _trackEvent method. You don’t even need to include the ga.js script.
Back to how ga.js works for a moment: if you use _trackEvent on a normal website, every time you call it, another __utm.gif file will be loaded with the event parameters – that is how the event details get back to Google.
The way we can track events in a Sencha Touch app is to load the __utm.gif file with certain parameters. You can find the list of possible parameters at http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html (scroll down to the bottom of the page).
The way I have implemented event tracking in my apps is by queuing the events, then batch loading the __utm.gif file when it has either a maximum number of events in the queue, or after a set interval, or if the app was offline for a while, then when it comes back online it will process the queue. I have a simple-to-use method with 3 parameters (category, action, label – these are the main parameters for event tracking) that I call when I want to track another event.
Hopefully this brief intro into how you might implement event tracking gives you enough to create your own implementation. If you are having trouble tracking events in your Sencha Touch (or other js app) then let me know and I should be able to share some of my code with you.
Nice approach, i just hit a similar problem, trying now to use a modified ga.js from local filesystem…