Using Google Analytics in Android
Even though Google Analytics is aimed squarely at web applications, they have written a library for Android which allows you to use their considerable reporting and analysis tools from within an App. It's very simple to use.
First get set up as an analytics user. This is free and results in you getting a code a bit like the maps api key. Then download the Android Analytics SDK and make put the jar in your apps lib dir (add to the build path too of course).
Next pick a sample Activity from one of your apps (preferably one you have deployed to the market so that your data is real, not just you poking around) into which you will place the tracking code. There is no point in putting tracking code throughout your app (or apps) until you know what you are doing.
There are a number of things you can track, but for now you just need to be sending back a row to the analytics server whenever a user carries out some action - say clicking a button.
Get an instance of the tracker (do this in onCreate):
mTracker = GoogleAnalyticsTracker.getInstance();
Start a new tracker session:
mTracker.startNewSession("UA-13302505-3", 30, this);
This provides your id to analytics along with a dispatch interval. This means that after 30 seconds of collecting analytics logs the data will be sent to the server in a burst. Alternatively you can call dispatch manually when some event happens in your app.
Then drop lines like this into your code wherever you want:
mTracker.trackPageView("/Dashboard");
'Dashboard' in this case is the name of one of my activities, but could be anything.
That's it. The reports update every 24 hours approx. It gives you a whole new perspective on your apps when you can see people using them.
I coupled this with some code from google I/O this year which provides a unique device ID. I am sending this back as a custom variable attached to the page view event.
First get set up as an analytics user. This is free and results in you getting a code a bit like the maps api key. Then download the Android Analytics SDK and make put the jar in your apps lib dir (add to the build path too of course).
Next pick a sample Activity from one of your apps (preferably one you have deployed to the market so that your data is real, not just you poking around) into which you will place the tracking code. There is no point in putting tracking code throughout your app (or apps) until you know what you are doing.
There are a number of things you can track, but for now you just need to be sending back a row to the analytics server whenever a user carries out some action - say clicking a button.
Get an instance of the tracker (do this in onCreate):
mTracker = GoogleAnalyticsTracker.getInstance();
Start a new tracker session:
mTracker.startNewSession("UA-13302505-3", 30, this);
This provides your id to analytics along with a dispatch interval. This means that after 30 seconds of collecting analytics logs the data will be sent to the server in a burst. Alternatively you can call dispatch manually when some event happens in your app.
Then drop lines like this into your code wherever you want:
mTracker.trackPageView("/Dashboard");
'Dashboard' in this case is the name of one of my activities, but could be anything.
That's it. The reports update every 24 hours approx. It gives you a whole new perspective on your apps when you can see people using them.
I coupled this with some code from google I/O this year which provides a unique device ID. I am sending this back as a custom variable attached to the page view event.
Comments
Post a Comment