Brais Gabin
Brais Gabin

Reputation: 5935

It's possible to configure a custom dimension at Tracker level?

I want to set a user scope dimension in Google Analytics using the SDK v4. The value of this dimension never changes in runtime.

When I created the dimension following this instructions the page gave me this code:

String dimensionValue = "SOME_DIMENSION_VALUE";
tracker.set(Fields.customDimension(1), dimensionValue);

This code is for SDK v3 and doesn't work at SDK4.

I readed this too: Custom Dimensions & Metrics - Android SDK v4. Their solution is to set the dimension EVERY time I send a page view, event, etc. That is mess! This dimension never changes. The sesion or user dimensions change less than the screen name which can be saved at tracker level.

Here my question: Is there a method to set the custom dimensions at tracker level like the Tracker.setScreenName?

Upvotes: 12

Views: 2872

Answers (2)

Shai Levy
Shai Levy

Reputation: 715

See: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cd_

So I think it should be:

String dimensionValue = "SOME_DIMENSION_VALUE";
tracker.set("&cd1", dimensionValue); //custom dimension 1

Upvotes: 13

Kormie
Kormie

Reputation: 127

It seems the solution for this is actually quite simple, if a bit clumsy. The trick is to set the scope of the custom dimension or metric on any hit and Google Analytics will apply the value to all future and past hits within the scope.

…custom dimension values with user or session-level scope will apply to all hits in the current session, including past hits.

For my case, I've set a User level scope for my custom dimensions and made sure to set/send the data on my main screen view. This means I can't use automatic screen tracking for this screen, which is a bummer.

Upvotes: 0

Related Questions