I want to set user level custom variables using google analytics in android I can see there is lack of documentation and demo for this I want to know how to set custom variable using GA and I am referring to following link
https://support.google.com/analytics/answer/2709828#scope
but it is not helpfull at all code given in it is not in java and very confusing If anyone has proper sample related to it please share
And it is not clear at all how much time it will take to reflect these changes on GA dashboard there is no clarity while using google analytics.
Also there a sample a code given
// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
t.setScreenName("Home Screen");
// Send the custom dimension value with a screen view.
// Note that the value only needs to be sent once.
t.send(new HitBuilders.ScreenViewBuilder()
.setCustomDimension(1, "premiumUser")
.build()
);
Now can anyone explain what is value 1 stands and it comes from where for in above call and why I need to call setScreenName
Also I have referred below link as well but does not give any clear idea
https://support.google.com/analytics/answer/2709829?hl=en&ref_topic=2709827
Also I tried to create custom variable I observed that one custom variable Demographic is already there I guess it is default created by GA so now my custom variable will start with index 2 or 1 that is also a confusion.
In GA4, creating a custom dimension involves the following two steps: Sending an event parameter along with an event. Registering the logged event parameter as a custom dimension in the user interface.
To set up your custom definitions you need to go to your analytics account >property settings > custom definitions. Keep in mind however there is a limit of 40 custom definitions, that is 20 metrics & 20 dimensions, so try to make sure you pick things that actually benefit the way you study your analytics account.
Custom Dimensions and metrics are identified by an index: 1 to n. The first Custom dimension you create will have an index of 1. Before you can send custom dimension and metric values to Analytics, they must first be defined in an Analytics property in the Analytics UI or through the Management API. Each Analytics property has 20 available indices for custom dimensions, and another 20 indices available for custom metrics.
The sample you used is sending a screen view hit (hence why it is setting the screen name) and sending a value to the first custom dimension. However you can send the information on any event type you'd like. For example:
// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
// Build and send an Event.
t.send(new HitBuilders.EventBuilder()
.setCategory(getString(categoryId))
.setAction(getString(actionId))
.setLabel(getString(labelId))
.setCustomDimension(1, "premiumUser") // Set the first custom dimension value to premiumUser for this event.
.build());
When you query for the value of the custom dimension with the Analytics Reporting API you will identify the custom dimension by index aswell, ga:dimension1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With