[This place is by Alexander Lucas, an Android Developer Advocate unerect on state the world 5 minutes.Tim Bray]
With the constituent of bespoken variables to the Mobile Analytics SDK for Android, it strikes me as a beatific instance to cover something some of you might not hit known was possibleusing Google Analytics to easily road app usage. Using the ambulatory SDK is a handy artefact to intend real accumulation on how users interact with your Android apps. So today I'm feat to explain how to road practice of your covering with Google Analytics.
Prereqs Ahoy!
Before you verify soured running with this shiny newborn toy, theres a some things youll need to ordered up first:
Download the ambulatory SDK. Download and installation instructions are available in the getting started section of the Mobile SDK docs, but the summarized edition is:
Download the fix file from the download page
Put the libGoogleAnalytics.jar file in your projects /libs directory
Be trusty the mass lines are in your AndroidManifest.XML file:<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Youre feat to need a Google Analytics account. Go to google.com/analytics and ordered up an account if you dont already hit one. Then ordered up a strikingness for your Android application. When youre finished youll wager a javascript piece to append into your site. Copy the part that looks aforementioned UA-XXXXXXX-X. Youll use this in the Android covering to tell Analytics which strikingness the accumulation is existence dispatched for.
Get Tracking
Previous Google Analytics users are feat to find a lot of this familiar. In fact, weve made a saucer of ownership the programme as old as possible.
First, intend your tracker object, and initialize it using the UA cipher for the Analytics strikingness you poverty to track. It makes the most significance to do this in the onCreate() method for your state main, so it exclusive fires when your covering starts up.
GoogleAnalyticsTracker tracker;protected vacuum onCreate(Bundle savedInstanceState) { ... tracker = GoogleAnalyticsTracker.getInstance(); tracker.start(UA-1234-1, this); }The ambulatory SDK provides support for the 3 essential types of accumulation dispatched to the Google Analytics servers: Pageviews, events, and bespoken variables.
Pageviews
A pageview is a accepted effectuation to manoeuvre reciprocation intensity to a traditional website. Given that this is feat into an Android app and not a website, its feat to be up to you to modify what a pageview means. Depending on the type of app, apiece Activity or assorted views within the aforementioned state (for instance, assorted tabs within a TabActivity) could count as a pageview.
Whenever you poverty to causing a pageview, call the trackPageView() method. It exclusive takes digit parameter, the URL you poverty a pageview counted towards.
tracker.trackPageView("/HomeScreen");Pageviews attain the most significance as flooded concealment transitions, which in most cases module stingy digit pageview per Activity. Therefor it makes the most significance to place the call to trackPageView in the onCreate() method for apiece state in your application. An exception would be if you were using a TabActivity, or other scenario where there were multiple full-screen transitions which every occurred within the aforementioned Activity, and conceptually mapped to seperate full-screen pages existence viewed.
Events
In Analytics, events are fashioned to road individual interaction to that doesnt transpose to pageviews, aforementioned hitting play/pause/stop in a multimedia app. This maps rattling substantially to Android usageAny modify of interaction, from hitting certain buttons to adding/removing accumulation from the datastore, crapper be tracked using Events.
Events are a little more complicated than pageviews, but meet slightly. Instead of 1 parameter, you hit 4: Category, Action, Label (optional), Value (optional).
To wager how to attain use of these, lets imagine you had a media player application, and wanted to road how some times play, pause, and kibosh were clicked. The cipher would countenance aforementioned this:
playButton.setOnClickListener(new OnClickListener() { @Override open vacuum onClick(View v) { ... tracker.trackEvent( "Media Player", // Category "Click", // Action "Play", // Label 0); // Value } }); pauseButton.setOnClickListener(new OnClickListener() { @Override open vacuum onClick(View v) { ... tracker.trackEvent( "Media Player", // Category "Click", // Action "Pause", // Label 0); // Value }); stopEventButton.setOnClickListener(new OnClickListener() { @Override open vacuum onClick(View v) { ... tracker.trackEvent( "Media Player", // Category "Click", // Action "Stop", // Label currentVideo.getPositionInSeconds()); // Value }); myMediaPlayer.setFinishedListener(new FinishedListener() { @Override open vacuum onFinished(View v) { ... tracker.trackEvent( "Media Player", // Category "Video Finished", // Action "Stop", // Label currentVideo.getLengthInSeconds()); // Value });Remember that in the Google Analytics scheme interface, this accumulation is displayed hierarchicallyFor instance, if you click on Categories in the left nav, and then on Media Player, youll wager a itemize of every the assorted doable values of Action which hit happened in the media Player category. Clicking on Click module show every the labels which were dispatched in the Media Player collection with an state of Click.
The 4th parameter, value, is optional, and behaves differently from the others. Its meant to be cumulative; In this example, Im sending the turn of recording watched when a recording is either stopped or allowed to finish. This is aggregated server-side, and when I go to countenance at my accumulation Ill be healthy to wager the amount instance grouping hit spent watching videos using my application.
Custom Variables
The newborn hotness! Custom variables are name-value unify tags that you crapper append in your tracking cipher in visit to refine Google Analytics tracking. The easiest artefact to conceive of this is as meta-data concomitant your pageviews and events. Using this metadata, it becomes easy to split soured and countenance at segments of your data, much the aforementioned artefact you use labels in Gmail. One Android-specific warning would be to hit a AppType position with Full or Lite depending on whether the individual has the flooded edition of the app or not. You could then use the Analytics scheme programme to countenance at exclusive the Lite users, and wager how their practice / userbase differs from the Full segment. Custom variables are a ridiculously coercive analytical tool, but theyre also a deep topic. I heartily propose gift the docs a once-through before implementing them in your Android application. Especially attain trusty to feature the section on scoping. Twice. Im stingy it... Ill wait.
There are 4 parameters in a bespoken variable: Index (1 to 5 inclusive), Name, Value, and Scope (Optional, defaults to Page Scope).
The place in your cipher where setCustomVar() module be called depends largely on what orbit that uncertain module be:
Visitor scope: disposition erst the prototypal instance your covering is separate on a device. Dont create some bespoken variables at the aforementioned index, or they module overwrite the prototypal one. Useful for sending accumulation most which edition of the app is existence used, what category of phone, lite vs flooded edition of the app, or anything that wont modify during the lifetime of the installation of that application.
Session scope: disposition erst at the beginning of every Activity startup. Will administer to every pageviews and events for the lifecycle of the activity, unless a assorted bespoken uncertain is created at the aforementioned index.
Page scope: disposition correct before trackEvent or trackPageView that the bespoken uncertain should administer to, every instance that method is called. If no orbit is specified, this is the default.
The call to ordered a bespoken uncertain module countenance aforementioned the following:
// Scopes are encoded to integers: Visitor=1, Session=2, Page=3tracker.setCustomVar(1, "Navigation type", "Button click", 3);Choose a Dispatch Mode
In visit to optimize for shelling life, a letter isnt actually dispatched discover to the computer every instance you fire a pageview or bespoken variable. Instead, every the pageviews, events, and their related bespoken variables are stored in a local SQLITE database until theyre dispatched as a group to the server. You crapper ordered this up to happen digit of two ways: Either hit the story become automatically every n seconds, or manually when you call story in code. The fashion is chosen when you call the move method on your tracker.
Manual story looks aforementioned this:
// No instance increment dispatched as a parametertracker.start(UA-1234-1, this);// disposition this when you poverty to beam the whole circumstance line to the servertracker.dispatch();The timed semiautomatic story looks similar, but sends an extra constant (the number of seconds between dispatches). In timed dispatch, you never hit to manually call dispatch.
// Dispatch every queued pagevies/events every 300 seconds (5 minutes)tracker.start("UA-YOUR-ACCOUNT-HERE", 300, this);Its essential to remember that Google Analytics uses the timestamp for when it receives your data, not when the actualised pageview/event occurred. This crapper potentially lead to inaccurate Analytics data, since events crapper be dispatched on assorted days than when they occurred, so verify care to story regularly.
The modify result
Lets go back to that onCreate() method we utilised to instantiate the tracker earlier, and wager what it looks aforementioned with every the pieces in place:
GoogleAnalyticsTracker tracker;protected vacuum onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);tracker = GoogleAnalyticsTracker.getInstance();tracker.start(UA-1234-1, this);if(isFirstTimeRunningApplication()) { tracker.setCustomVar(1, App Type, Demo, 1);}tracker.trackPageView("/HomeScreen");}How to countenance at every this data
There are two ways you crapper move this. First, Google Analytics has a pretty snazzy scheme interface, which does a rattling beatific employ of surfacing useful aggregation for you. If youre newborn to Analytics and dont rattling undergo what youre hunting for yet, the scheme programme is a enthusiastic artefact to explore your accumulation and understand your users.
If you already hit a strong idea of the questions you poverty to communicate (app practice crossways versions of the Android platform, ontogeny rates, time-in-app per demo individual vs flooded user, how some grouping vex level 3 on their prototypal try, etc), and meet poverty to automate the asking, Google Analytics also has a stylish accumulation goods API, with computer libraries to facilitate the querying of your accumulation in Java, Python, JavaScript, and C#.
Abiding by the TOS
Google Analytics comes with its possess TOS, and its essential to feature and stay by it. The essential bit, especially since this module be utilised inside Android applications, is that you cannot beam personally identifying information to Analytics servers. This is a big deal. It means, for instance, that a visitor-level bespoken uncertain cannot include a sound number, prototypal name, or telecommunicate address. Less intuitively, but ease important, it effectuation that if this covering is a computer to a scheme covering (say, CRM code or a shopping site), you also cannot store aggregation in Analytics which crapper be combined with your possess backend code to refer the user, much as individual ID or a transaction ID same to the digit stored on your scheme backend.
Thanks
basyar.com
Tidak ada komentar:
Posting Komentar