[This place is by herb Lucas, an Android Developer Advocate unerect on action the world 5 minutes.Tim Bray]
With the constituent of bespoken variables to the Mobile Analytics SDK for Android, it strikes me as a good happening to counterbalance 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 actualised 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 take soured running with this shiny newborn toy, theres a some things youll requirement to set up first:
Download the ambulatory SDK. Download and artefact instructions are available in the getting started country of the Mobile SDK docs, but the summarized edition is:
Download the zip enter from the download page
Put the libGoogleAnalytics.jar enter 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 requirement a Google Analytics account. Go to google.com/analytics and set up an statement if you dont already hit one. Then set up a strikingness for your Android application. When youre done youll wager a javascript snippet to insert into your site. Copy the part that looks same UA-XXXXXXX-X. Youll ingest 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 encounter a lot of this familiar. In fact, weve made a point 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 hold for the 3 main types of accumulation dispatched to the Google Analytics servers: Pageviews, events, and bespoken variables.
Pageviews
A pageview is a standard effectuation to manoeuvre traffic volume 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 decide what a pageview means. Depending on the type of app, apiece Activity or assorted views within the same state (for instance, assorted tabs within a TabActivity) could calculate as a pageview.
Whenever you poverty to trigger a pageview, call the trackPageView() method. It exclusive takes digit parameter, the come you poverty a pageview counted towards.
tracker.trackPageView("/HomeScreen");Pageviews attain the most significance as flooded concealment transitions, which in most cases module mean 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 binary full-screen transitions which every occurred within the same 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, same touch play/pause/stop in a transmission app. This maps rattling substantially to Android usageAny form of interaction, from touch destined 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 ingest 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 same 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 utter on Categories in the mitt 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 action 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 amount 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 total happening people hit spent watching videos using my application.
Custom Variables
The newborn hotness! Custom variables are name-value unify tags that you crapper insert in your chase cipher in order to refine Google Analytics tracking. The easiest artefact to conceive of this is as meta-data accompanying your pageviews and events. Using this metadata, it becomes cushy to split soured and countenance at segments of your data, much the same artefact you ingest labels in Gmail. One Android-specific warning would be to hit a AppType status with Full or Lite depending on whether the individual has the flooded edition of the app or not. You could then ingest 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 preposterously powerful analytical tool, but theyre also a unfathomable topic. I cordially recommend gift the docs a once-through before implementing them in your Android application. Especially attain trusty to feature the country on scoping. Twice. Im mean 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 titled depends mostly on what orbit that uncertain module be:
Visitor scope: disposition erst the first happening your covering is separate on a device. Dont create any bespoken variables at the same index, or they module overwrite the first one. Useful for sending accumulation about which edition of the app is existence used, what category of phone, fatless vs flooded edition of the app, or anything that wont modify during the period of the artefact 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 same index.
Page scope: disposition correct before trackEvent or trackPageView that the bespoken uncertain should administer to, every happening that method is called. If no orbit is specified, this is the default.
The call to set a bespoken uncertain module countenance same 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 order to behave for battery life, a request isnt actually dispatched out to the computer every happening you blast 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 set this up to happen digit of digit 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 same this:
// No happening increment dispatched as a parametertracker.start(UA-1234-1, this);// disposition this when you poverty to beam the entire event queue 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 life than when they occurred, so take tending 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 same 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 digit ways you crapper move this. First, Google Analytics has a pretty snazzy scheme interface, which does a rattling good employ of surfacing multipurpose information for you. If youre newborn to Analytics and dont rattling undergo what youre looking for yet, the scheme programme is a great artefact to explore your accumulation and see your users.
If you already hit a brawny intent of the questions you poverty to communicate (app practice across versions of the Android platform, ontogeny rates, time-in-app per demo individual vs flooded user, how some people beat level 3 on their first try, etc), and meet poverty to automate the asking, Google Analytics also has a stylish accumulation goods API, with computer libraries to assist 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 abide by it. The essential bit, especially since this module be utilised exclusive 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, first name, or telecommunicate address. Less intuitively, but still important, it effectuation that if this covering is a computer to a scheme covering (say, CRM code or a shopping site), you also cannot accumulation information in Analytics which crapper be combined with your possess backend code to refer the user, such as individual ID or a dealings ID same to the digit stored on your scheme backend.
Thanks
basyar.com
Tidak ada komentar:
Posting Komentar