The number of sessions is multiplied when I use the Google Analytics Android SDK v4

As my application, the number of sessions was about 1000-2000 when I used Google Android for Android SDK v3. enter image description here

But when I upgrade from v3 to v4, the number of sessions increases to 4000-5000. enter image description here

This is global_tracker.xml:

<?xml version="1.0" encoding="utf-8"?> 

 <!-- Enable automatic Activity measurement --> <bool name="ga_autoActivityTracking">true</bool> <!-- The screen names that will appear in reports --> <string name="ga_trackingId">xx-xxxx-xx</string> 

And this is what I did in the Application.java file:

 public class ABCApplication extends Application { ... private static Tracker t; ... public synchronized Tracker getTracker() { if (this.t == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); this.t = analytics.newTracker(R.xml.global_tracker); } return t; }} 

And this is the MainActivity.java file:

 public class MainActivity { @Override public void onStart() { super.onStart(); Tracker t = ((ABCApplication) this.getApplication()).getTracker(); t.send(new HitBuilders.EventBuilder().setCategory("app").setAction("app_launch") .setLabel("start_google_analytics").build()); } ...} 

What is the cause of this problem? And how can I solve it?

+7
android session google-analytics
source share
3 answers

As we found out, the main reason for this problem is automatic activity tracking. When automatic activity tracking is disabled, GA will close the userโ€™s session after 30 minutes have passed since the last event. If active activity tracking is enabled, GA will end the session after the application enters the background or the user exits the application. Then launching the application in a short period of time will create a new session in GA.

+5
source share

Perhaps this has something to do with setting the timeout

Try customizing this in xml:

 <resources> <integer name="ga_sessionTimeout">300</integer> </resources> 

https://developers.google.com/analytics/devguides/collection/android/v4/sessions

+1
source share

Add this to your manifest:

 <!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background dispatching on non-Google Play devices --> <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver" android:enabled="true"> <intent-filter> <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" /> </intent-filter> </receiver> <service android:name="com.google.android.gms.analytics.AnalyticsService" android:enabled="true" android:exported="false"/> 

I just did some preliminary testing, but after I added this, it seems like it is reporting the session and duration again. Code snippet taken from: https://developers.google.com/analytics/devguides/collection/android/v4/#manifest

0
source share

All Articles