πŸ“œ ⬆️ ⬇️

Work with the new version of Google Analytics v2 on the example of Android applications

Not so long ago , the new Google Analytics SDK (further GA) for mobile platforms under version 2 was announced . Now it is in beta status. But anyone can ask Google for access to the toolkit .



We in our project have already tried a new version adapted for mobile applications. And I am in a hurry to share my impressions and talk about using the SDK using the example of an Android application.

')

Account setup


Three scenarios:

There is no GA account or application tracking account.


  1. First of all, we create a new GA account at www.google.com/analytics/web/#management/Accounts , having registered beforehand (this is simple, I will not describe everything with your permission in steps).
  2. Click above the table "+ New Account".
  3. Fill all the fields, click "get tracking id".
  4. And here is the cherished key in front of 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.

  1. Right on the top orange bar click "Admin".
  2. Select the "Profiles" tab.
  3. Click the "New Profile" button.
  4. Select "App", give the name.

All the same key that you used earlier will work now.

Now the received key can be safely inserted into our application.

Initial configuration in the application


Add libGoogleAnalyticsV2.jar library to your project libs folder

Create an empty xml file in res / values ​​/ analytics.xml

<?xml version="1.0" encoding="utf-8" ?> <resources> <string name="ga_trackingId">   UA-111111-1</string> <string name="ga_appVersion">1.1.0 Google Play</string> <bool name="ga_reportUncaughtExceptions">true</bool> <bool name="ga_debug">true</bool> <bool name="ga_autoActivityTracking">true</bool> </resources> 


ga_appVersion - can be removed if the version is specified in the manifest. But I have an application for different markets, and in order to track the activity of users of different markets, I override versions like 1.1 Play and 1.1 Samsung

ga_reportUncaughtExceptions - in principle, BugSense is used to track errors in a project, but you can also track them in analytics

ga_debug - enable, in order to read in the log whether the analyst has earned correctly after the settings

ga_autoActivityTracking - for some reason, without this activation tracking did not work, despite the fact that they are forcibly tracked in the project

Now let's set up our activations.
For the convenience of all of them inherit from TrackingActivity. In it we will write the following code:

 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 in Manifest.xml there should be a resolution:
<uses-permission android:name="android.permission.INTERNET" />

Advanced configuration in the application


You may also need to explore 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 strings describing the event. For example, call trackEvent("Clicks", "MainActivityClicks", "onSaveCarLocationClick", null);
And we will create an event of the category Clicks, 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 strings, and loadTime is time in milliseconds

To get loadTime, we call System.getCurrentTimeInMillis before starting the operation and after the execution we call it again. The difference between 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 navigate to the Google Play page of your application - you can track this by sending not a direct link to Google Play, but analytics specially generated on the website at the bottom . Immediately by the way, you can read more about the implementation of this tracking. It requires setting a special BroadcastReceiver to interact with Google Play.

Enjoyment 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.
Go to the analytics page . And go to the profile.

First of all, let's look in real time at who is using the application right now.
Go to the Home tab -> Realtime -> Overview



Here, of particular interest is the number of users and the names of the screens that they have open.

Now we’ll go to the Standart Reporting -> App Overview tab, it summarizes many of the data collected by analytics.
Choose Standart Reporting -> Acquisitions -> New users

Here you can clearly see the 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.

Standart Reporting tab -> Users -> Overview

The button on the left above the graph allows you to display various metrics. Somehow: open screens, application usage sessions, users. All this is displayed on the chart by day.

Open Standart Reporting -> Users -> Devices and Network -> Devices

It displays statistics on the devices on which users run the application.

Standart Reporting -> Engagement -> Events presents data that helps us understand exactly which screens are popular with users and how much time users spend on them.

If the application keeps track of user actions, then their statistics can be viewed in the Standard Reporting tab -> Engagement -> Events

Here you can see the number of all user actions with division into categories, such as we specified in the code.
Well, on the graph you can clearly see how often events happened on different days.

Of course, this is only a superficial overview of the capabilities of Google Analytics. Waiting for comments from experienced analysts, with tips on using this powerful tool.

Source: https://habr.com/ru/post/148160/


All Articles