Automatically detecting Google Analytics activity - can you exclude one action from this?

Automatic activity detection is great - besides my MainActivity there are a bunch of different fragments with a navigation box (for example, Google Play Music or the Play Store). I use a manual screen to track fragments in this activity.

Therefore, automatic screen tapping for my MainActivity pointless and pollutes my statistics. Is it possible to exclude tracking of my MainActivity in this way?

Link: https://developers.google.com/analytics/devguides/collection/android/v4/screens#automatic

+6
source share
1 answer

Just set enableAutoActivityTracking(false) to the Tracker instance obtained in this operation.

Assuming you created the getDefaultTracker() method in your application class, as described in white papers , you can create a parent class for your application that can change the automatic tracking behavior on demand:

 public abstract class ParentActivity extends Activity { Tracker mTracker = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getTracker(); } /* Obtains Google Analytics Tracker for this activity */ Tracker getTracker() { if (mTracker == null) { AnalyticsApplication application = (AnalyticsApplication) getApplication(); mTracker = application.getDefaultTracker(); // Enable or disable auto-tracking for this activity mTracker.enableAutoActivityTracking(shouldAutoTrack()); } return mTracker; } /* Defines whether this activity should enable auto-track or not. Default is true. */ protected boolean shouldAutoTrack() { return true; } } 

Your main activity is simply to extend ParentActivity and override the shouldAutoTrack method to return false:

 public class MainActivity extends ParentActivity { /* Disable auto-tracking for this activity */ protected boolean shouldAutoTrack() { return false; } } 
0
source

All Articles