Working with the new version of Google Analytics v2 using an Android application as an example
Not so long ago , a new Google Analytics SDK (hereinafter GA) was announced for mobile platforms under version 2. Now it is in beta. But anyone can ask Google to give access to the toolkit .

In our project, we have already tried a new version adapted for mobile applications. And I hasten to share my impressions and talk about using the SDK as an example of an Android application.
Three scenarios:
We do everything the same as in the previous paragraph, except for the first step.
Everything, the same key that you used earlier will work now.
Now the received key can be safely inserted into our application.
Add the library libGoogleAnalyticsV2.jar to the libs folder of your project.
Create an empty xml file in res / values / analytics.xml
ga_appVersion - can be deleted if the version is specified in the manifest. But I have an application for different markets, and to track the activity of users of different markets I redefine versions as 1.1 Play and 1.1 Samsung
ga_reportUncaughtExceptions - in principle, BugSense is used to track errors in the project , but you can track them in the
ga_debug analytics as well - turn it on to read whether the analytics worked correctly in the log after the
ga_autoActivityTracking settings - for some reason, activity tracking did not work without this, despite the fact that they track forcibly in the project
Now we’ll configure our activities.
For the convenience of all, we will inherit them from TrackingActivity. We will write the following code in it:
in res / values / bools.xml for convenience there is a field that disables analytics, for example, when debugging
That's all - this is the minimum set of settings. And of course, there should be a permission in Manifest.xml:
You may also need to research your user preferences. You can track any events, for this it is enough to perform:
where catogory, action and label are the lines describing the event. For example, we call
And we will create an event of the Clicks category, with the name of the action MainActivityClicks and the label onSaveCarLocationClick.
To track the application’s usage time and the execution time of some operations, you can call
where category, name and label are the strings, and loadTime is the time in milliseconds.
To get loadTime, before the operation starts, call System.getCurrentTimeInMillis and call it again after execution. The difference of these values is passed as loadTime.
If you have a large Internet or other PR company, and you want to know the sources from which users go to the Google Play page of your application - you can track this by transferring not a direct link to Google Play, but specially generated analytics on the website at the bottom . Here, by the way, you can read more about the implementation of this tracking. It requires setting up a special BroadcastReceiver to interact with Google Play.
The most delicious begins when the application falls into the hands of users. Now we have statistics, and we can see it in analytics.
We go to the analytics page . And go to the profile.
First of all, let's see in real time who is using the application right now.
Go to the tab Home -> Realtime -> Overview. Of particular interest here is the number of users and the names of the screens that they have open. Now let's go to the Standart Reporting -> App Overview tab, it summarizes the data from many of the data collected by analytics. Choose Standart Reporting -> Acquisitions -> New users


Here you can clearly see statistics on new users for the period selected at the top right. You can see how many users, which versions and from which countries first launched the application.
Tab Standart Reporting -> Users -> Overview The button on the left above the graph allows you to display various metrics. Something like: open screens, application use sessions, users. All this is displayed on the chart by day. Open Standart Reporting -> Users -> Devices and Network -> Devices Here you can see statistics on the devices on which users started the application. Standart Reporting -> Engagement -> Events presents data that helps us understand which screens are popular with users and how much time users spend on them.


If the application is tracking user actions, then their statistics can be viewed in the Standart Reporting -> Engagement -> Events tab. Here you can see the number of all user actions with the division into categories, such as we specified in the code. Well, the graph clearly shows how often the events took place on different days. Of course, this is just a superficial overview of the capabilities of Google Analytics. I look forward to comments from experienced analysts, with tips on using this powerful tool.


In our project, we have already tried a new version adapted for mobile applications. And I hasten to share my impressions and talk about using the SDK as an example of an Android application.
Account setup
Three scenarios:
There is no GA account, no account with tracking application
- First of all, create a new account in GA www.google.com/analytics/web/#management/Accounts , pre-registering (it's simple, I will not describe everything with your permission in steps).
- Click at the top of the table "+ New Account".
- Fill in all the fields, click "get tracking id".
- And here is the cherished key before us.
There is a GA account, but there is no account with application tracking
We do everything the same as in the previous paragraph, except for the first step.
There is a GA account, and the application is already being tracked from it
- On the right on the upper orange strip, click "Admin".
- Select the “Profiles” tab.
- Click the “New Profile” button.
- Select "App", give a name.
Everything, the same key that you used earlier will work now.
Now the received key can be safely inserted into our application.
Initial setup in the application
Add the library libGoogleAnalyticsV2.jar to the libs folder of your project.
Create an empty xml file in res / values / analytics.xml
ваш ключ вида UA-111111-1 1.1.0 Google Play true true true ga_appVersion - can be deleted if the version is specified in the manifest. But I have an application for different markets, and to track the activity of users of different markets I redefine versions as 1.1 Play and 1.1 Samsung
ga_reportUncaughtExceptions - in principle, BugSense is used to track errors in the project , but you can track them in the
ga_debug analytics as well - turn it on to read whether the analytics worked correctly in the log after the
ga_autoActivityTracking settings - for some reason, activity tracking did not work without this, despite the fact that they track forcibly in the project
Now we’ll configure our activities.
For the convenience of all, we will inherit them from TrackingActivity. We will write the following code in it:
public class TrackedActivity extends Activity{
protected void onCreate(Bundle savedInstanceState, String tag) {
super.onCreate(savedInstanceState);
EasyTracker.getInstance().setContext(this);
//если в наследниках в onCreate мы не будем обращаться к EasyTracker, то можно строчку закомментировать
}
@Override
protected void onStart() {
if(getResources().getBoolean(R.bool.analytics_enabled)) {
EasyTracker.getInstance().activityStart(this);
}
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
EasyTracker.getInstance().activityStop(this);
}
}
in res / values / bools.xml for convenience there is a field that disables analytics, for example, when debugging
That's all - this is the minimum set of settings. And of course, there should be a permission in Manifest.xml:
Advanced customization in app
You may also need to research your user preferences. You can track any events, for this it is enough to perform:
EasyTracker.getTracker().trackEvent(category, action, label, null);where catogory, action and label are the lines describing the event. For example, we call
trackEvent("Clicks", "MainActivityClicks", "onSaveCarLocationClick", null);And we will create an event of the Clicks category, with the name of the action MainActivityClicks and the label onSaveCarLocationClick.
To track the application’s usage time and the execution time of some operations, you can call
EasyTracker.getTracker().trackTiming(category, loadTime, name, label);where category, name and label are the strings, and loadTime is the time in milliseconds.
To get loadTime, before the operation starts, call System.getCurrentTimeInMillis and call it again after execution. The difference of these values is passed as loadTime.
If you have a large Internet or other PR company, and you want to know the sources from which users go to the Google Play page of your application - you can track this by transferring not a direct link to Google Play, but specially generated analytics on the website at the bottom . Here, by the way, you can read more about the implementation of this tracking. It requires setting up a special BroadcastReceiver to interact with Google Play.
Enjoy the results
The most delicious begins when the application falls into the hands of users. Now we have statistics, and we can see it in analytics.
We go to the analytics page . And go to the profile.
First of all, let's see in real time who is using the application right now.
Go to the tab Home -> Realtime -> Overview. Of particular interest here is the number of users and the names of the screens that they have open. Now let's go to the Standart Reporting -> App Overview tab, it summarizes the data from many of the data collected by analytics. Choose Standart Reporting -> Acquisitions -> New users


Here you can clearly see statistics on new users for the period selected at the top right. You can see how many users, which versions and from which countries first launched the application.
Tab Standart Reporting -> Users -> Overview The button on the left above the graph allows you to display various metrics. Something like: open screens, application use sessions, users. All this is displayed on the chart by day. Open Standart Reporting -> Users -> Devices and Network -> Devices Here you can see statistics on the devices on which users started the application. Standart Reporting -> Engagement -> Events presents data that helps us understand which screens are popular with users and how much time users spend on them.


If the application is tracking user actions, then their statistics can be viewed in the Standart Reporting -> Engagement -> Events tab. Here you can see the number of all user actions with the division into categories, such as we specified in the code. Well, the graph clearly shows how often the events took place on different days. Of course, this is just a superficial overview of the capabilities of Google Analytics. I look forward to comments from experienced analysts, with tips on using this powerful tool.
