Google Analytics
Google Analytics is a service offered by Google that generates detailed statistics about a website's traffic and traffic sources and measures conversions and sales. The product is aimed at marketers as opposed to webmasters and technologists from which the industry of web analytics originally grew. It is the most widely used website statistics service.
Categories
Libraries
Getting Started
Update your AndroidManifest.xml
file by adding the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Add the send methods to the onStart()
and onStop()
methods of each of your Activities as in the following example:
package com.example.app;
import android.app.Activity;
import com.google.analytics.tracking.android.EasyTracker;
/**
* An example Activity using Google Analytics and EasyTracker.
*/
public class myTrackedActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
... // The rest of your onStart() code.
EasyTracker.getInstance(this).activityStart(this); // Add this method.
}
@Override
public void onStop() {
super.onStop();
... // The rest of your onStop() code.
EasyTracker.getInstance(this).activityStop(this); // Add this method.
}
}
When you use EasyTracker, global configuration settings are managed using resources defined in XML. Create a file called analytics.xml
in your project's res/values
directory and add the following resources:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<!--Replace placeholder ID with your tracking ID-->
<string name="ga_trackingId">UA-XXXX-Y</string>
<!--Enable automatic activity tracking-->
<bool name="ga_autoActivityTracking">true</bool>
<!--Enable automatic exception tracking-->
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
Your lint checker may warn you about the use of the figure dash ('-') in your tracking ID. You can suppress that warning by adding additional attributes to your <resources> tag:
Important: Do not encode dashes in the ga_trackingId
string. Doing so will prevent you from seeing any data in your reports.