0

We are developing google analytics for an android app, we have seen that you can add custom dimension/metrics to an event by doing:

t.send(new HitBuilders.ScreenViewBuilder()
     .setCustomDimension(1, "premiumUser")
     .build()
);

But I understand that that custom dimension will be sent just on that event. Is there a way to set it to tracker so it will be automatically send to all events/screens? For instance, something like:

t.set("cd<1>", "premiumUser");

Another question, do we have to add: t.setScreenName(null) in every onDestroy of a fragment/activity if we are sending the setScreenName on the onCreate method?

Thanks in advance

FVod
  • 2,245
  • 5
  • 25
  • 52

1 Answers1

0

If we need a screen to be recorded in Analytics, We need to send Screen view on every onCreate like

t.send(new HitBuilders.AppViewBuilder().setCustomDimension(cusDimensionId, dimensionValue).build());

There is no need to add t.setScreenName(null) on onDestroy

Get Tracker :

public synchronized Tracker getCustomDimensionTracker(TrackerName trackerId) {
    if (!mCustomDimensionTrackers.containsKey(trackerId)) {

        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        if (trackerId == TrackerName.CUSTOM_DIMENSION_TRACKER) {
            Tracker t = analytics.newTracker(App.get().getResources()
                    .getString(R.string.google_analytics_key));
            mCustomDimensionTrackers.put(trackerId, t);
        }
    }
    return mCustomDimensionTrackers.get(trackerId);
}
Logic
  • 2,230
  • 2
  • 24
  • 41
  • But the custom dimension will be send just on that event, what if we want to send the custom dimension in all events. Can we do something like: t.set("cd<1>", "premiumUser");? – FVod Jan 27 '16 at 12:58
  • Isn't t.setScreenName(null) required in order to clear the screen name from where all events are sent? If we forget to send the screen name on an activity, then the events would be sent from the old screen – FVod Jan 27 '16 at 13:00
  • we need to call this for when ever we want. If we use the same tracker, it might make wrong count. It ends up recording one dimension more than once. I have experienced it :D – Logic Jan 27 '16 at 13:01
  • see my edit, we get tracker from synchronized so that it will not use previous tracker – Logic Jan 27 '16 at 13:03