Google Analytics for Android Applications.


Note: Most of the contents of this post is taken from Google Analytics SDK for Android. Please go through this site for details.

Overview.

The Google Analytics for Mobile Apps SDKs provide an interface for tracking activity within mobile apps and reporting that activity to Google Analytics. For example you can use this SDK to calculate visits, session length, bounce rate and unique visitors. Tracking mobile applications has some structural variations from tracking website pages.

This SDK uses a tracking model that is designed to track visitors to traditional websites and interaction with widgets in traditional web pages. For this reason, the terms used below reflect the conventional website tracking model and are being mapped over to tracking mobile applications. You should be familiar with Analytics tracking in order to understand how this SDK works.
Use the mobile tracking SDK to track your phone applications with the following Analytics interaction types:

Pageview Tracking
A pageview is a standard means to measure traffic volume to a traditional website. Because mobile apps don’t contain HTML pages, you must decide when (and how often) to trigger a pageview request. Also, since pageview requests are designed to report on directory structures, you should provide descriptive names for the requests to take advantage of page path naming in the Content reports in Analytics. The names you choose will be populated in your Analytics reports as page paths even though they are not actually HTML pages, but you can use this to your advantage by structuring paths to provide additional groupings for your calls.

Event Tracking
In Analytics, events are designed to track user interaction to web page elements distinctly from pageview requests. You can use the Event Tracking feature of Google Analytics to make additional calls that will be reported in the Event Tracking section of the Analytics report interface. Events are grouped using categories and may also use per-event labels, which provides flexibility in reporting. For example, a multimedia app could could have play/stop/pause actions for its video category and assign a label for each video name. The Google Analytics reports would then aggregate events for all events tagged with the video category. For more information on Event Tracking, see the Event Tracking Guide

Ecommerce Tracking
Use the Ecommerce tracking feature to track shopping cart transactions and in-app purchases. To track a transaction, use the Transaction class to represent the overall purchase information as well as the Item class to represent each product in the shopping basket. Once collected, the data can then be viewed in the Ecommerce reporting section of the Google Analytics interface. For more information on Ecommerce Tracking, see the Ecommerce Tracking Guide.

Custom Variables
Custom variables are name-value pair tags that you can insert in your tracking code in order to refine Google Analytics tracking. For more information on how you can use custom variables, read the Custom Variable Guide.

Getting Started

First thing you need is an account at Google Analytics. If you don’t have access to google analytics then go ahead and get it. It is FREE.

Now when you have an account then add a website profile. While creating your website profile you will be asked for website url. Since we are not actually tracking any wesite here, you can give any dummy url here. It will be best if you give your reverse of application’s package name. It makes it easy to manage.

For example, I have given the url as http://sample.analytics.techjini.com.

Once you create the profile you will get Web Property ID. Secure it somewhere, you will need this in your android application.

Save and Finish the profile and you will be able to see this newly created profile in Website Profiles list.

Getting started on client.

Before you get your hand dirty in google analytics, you need 2 things.
1. Android developer SDK
2. Google Analytics for Mobile Apps Android SDK

Setup

  • Add libGoogleAnalytics.jar to your project’s /libs directory.
  • Add the following permissions to your project’s AndroidManifest.xml manifest file:
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Using the SDK

Starting the Tracker

Obtain the tracker singleton by calling

GoogleAnalyticsTracker.getInstance()

. Then call its start method, passing the web property ID and activity being tracked. It is often convenient to call this method directly in the onCreate method of your Activity. For example:

package com.techjini.analytics.sample;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.google.android.apps.analytics.GoogleAnalyticsTracker;

public class SampleActivity extends Activity implements OnClickListener {

    private static final String APP_ID = "UA-10753031-2";
    private GoogleAnalyticsTracker tracker;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tracker = GoogleAnalyticsTracker.getInstance();

        // Start the tracker in manual dispatch mode...
        tracker.start(APP_ID, this);

        // ...alternatively, the tracker can be started with a dispatch interval
        // (in seconds).
        // tracker.start("UA-YOUR-ACCOUNT-HERE", 20, this);

        setContentView(R.layout.main);
        findViewById(R.id.button1).setOnClickListener(this);
        findViewById(R.id.button2).setOnClickListener(this);
        findViewById(R.id.button3).setOnClickListener(this);
    }

    /**
     * Handles click events on event generator button. This is the place where
     * we create events to track.
     */
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1:
            tracker.trackEvent("Clicks", // Category
                    "Button", // Action
                    "clicked", // Label
                    1); // Value
            break;
        case R.id.button2:
            // Add a Custom Variable to this pageview, with name of "Medium" and
            // value "MobileApp" and
            // scope of session-level.
            tracker.setCustomVar(1, "Navigation Type", "Button click", 2);
            // Track a page view. This is probably the best way to track which
            // parts of your application
            // are being used.
            // E.g.
            // tracker.trackPageView("/help"); to track someone looking at the
            // help screen.
            // tracker.trackPageView("/level2"); to track someone reaching level
            // 2 in a game.
            // tracker.trackPageView("/uploadScreen"); to track someone using an
            // upload screen.
            tracker.trackPageView("/testApplicationHomeScreen");
            break;
        case R.id.button3:
            tracker.dispatch();
            break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // Stop the tracker when it is no longer needed.
        tracker.stop();
    }
}

You can use

tracker.dispatch();

to force dispatch the tracked events.

To know about eCommerce tracking please refer Using Ecommerce Tracking

Now… If you know well how to use Google Analytics Reports then this is enough to capture any kind of information you need to enhance and improve your product.

Advertisements

12 comments

  1. Hi i got one problem in android i want to do json parsing in android but M not able to parse it can u help me if yes as soon as possible i will forward all the information

      1. Could you be more specific. I do not think any web service should return random objects.

  2. Build an application that communicates with an API and lists the products returned by the API
    API
    Endpoint: [URL]

    This URL returns a JSON array of 10 random objects.

    Following products may exist in the JSON object:

    Book
    Title
    Author
    Description
    Price
    Camera
    Model
    Picture
    Price
    Song
    Title
    Album
    Artist
    Genre

    ////This is the problem what I am facing on right now

  3. Howdy this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!

  4. I was suggested this website by my cousin. I am no longer positive whether or not this publish is written through him as nobody else know such precise about my problem. You’re wonderful! Thanks!

  5. Hey there just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same outcome.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s