Google Analytics logging all events with sc=start causing large number of sessions

271 views Asked by At

I am using following code to generate google analytic events from my Android application. However, whenever I call trackScreenView (see implementation below) , it seems like google is generating event with sc=start that indicates session start.

I see in the log something like this.

Hit delivery requested: ht=1481734927581, _s=538, _v=ma10.0.84,
a=1960698122, adid=XXXX, aid=AppName, an=AppName, ate=1, 
av=1.0.7.21, cd=ActivityName, cid=XXX, sc=start, 
sr=1080x1920, t=screenview, tid=UA-XXX, ul=en-us, v=1

Now this sc=start inflates session start counts enormously which drives us crazy. Do I need to explicitly create HitBuilder and add hit.put("&sc", "end") , none of the google sample code seem to be doing that.

I am using com.google.android.gms:play-services-analytics:10.0.1 in my code.

For reference here are various parameters google analytic uses: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters

And here is my code that interacts with GA.

  public AnalyticsHelper(Context context, SharedPreferences sharedPreferences) {
    this.context = context;
    this.sharedPreferences = sharedPreferences;
    GoogleAnalytics analytics = GoogleAnalytics.getInstance(context);
    if(analytics != null) {
      tracker = analytics.newTracker(context.getResources().getString(R.string.ga_trackingId));
      if(tracker != null) {
        tracker.enableAdvertisingIdCollection(true);
        tracker.enableAutoActivityTracking(true);
        tracker.enableExceptionReporting(true);
        if (!AnalyticsHelper.appStartEvent) {
          trackAppStartEvent();
          AnalyticsHelper.appStartEvent = true;
        }
      }
    }
  }

  private void trackAppStartEvent() {
    Timber.d("AnalyticsHelper send traceAppStartEvent");
    String cohort = getCohort();
    tracker.setScreenName(APP_START_SCREEN_NAME);
    Map<String, String> hit = new HitBuilders.EventBuilder().setCategory(EVENT_CATEGORY_ACTION)
            .setNewSession()
            .setAction(EVENT_ACTION_APP_START)
            .setLabel(APP_START_LABEL)
            .setCustomDimension(CUSTOM_DIMENTION_COHORT, cohort)
            .build();
    tracker.send(hit);
  }

  private void trackScreenView(String screenName) {
    if(screenName != null) {
      if (!screenName.isEmpty()) {
        Timber.d("AnalyticsHelper send trackScreenView %s",screenName);
        tracker.setScreenName(screenName);
        tracker.send(new HitBuilders.ScreenViewBuilder().build());
        Timber.d("trackScreenView: %s", screenName);
        AppsflyerHelper.trackScreenView(context, screenName);
        rateappRules.incrementRatemeMetric(SHARED_PREFS_SCREEN_COUNT);
      }
      else
        Timber.e("TrackScreenView screen name is non-null, but empty, not tracked");
    }
  }

I am also using following tracker config file.

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <string name="ga_trackingId">UA-XXXXX</string>
    <bool name="ga_autoActivityTracking">true</bool>
    <bool name="ga_anonymizeIp">false</bool>
    <bool name="ga_reportUncaughtExceptions">true</bool>
       <screenName name="com.myapp.OnboardngActivity">
        OnboardngActivity
    </screenName>
    <screenName name="com.myapp.MainActivity">
        MainActivity
    </screenName>
</resources>
0

There are 0 answers