简体   繁体   中英

Should we create instance of EasyTracker multime times when trying to send logs to Google Analytics dashboard

I am using Google Analytics in android project. For this wherever I'm sending analytics I'm creating object of EasyTracker class.

Suppose user is on First Activity then I'm creating the object of EasyTracker in onCreate so when user navigate to second activity then again I'm creating object of EasyTracker in onCreate of second activity.

Should we create object of EasyTracker once only and use it same in entire application or this does not matter. I guess that by creating two object of EasyTracker Google Analytics is assuming that there are two real time users but exact is only one.

EasyTracker easyTracker = EasyTracker.getInstance(ActivityMain.this);

Thanks in advance.

Look at sample:

  @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.
  }

https://developers.google.com/analytics/devguides/collection/android/v3/

It seems that EasyTracker is singletone and you should call getInstance every time.

You should consider switching to a newer v4 version of the Google Analytics SDK for Android. v4 of the API support automatic activity reporting - Tracker.enableAutoActivityTracking . Once you enable automatic tracking it does the screen reporting for you. Easy tracker is v2/v3 of the API and doesn't support many new features added to Google Analytics like demographics reporting. Google only maintains the latest version of the SDK so v2/v3 might not work that well on newer versions of Android.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM