Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Google Analytics Custom Dimensions

I've been reading the Custom Dimensions documentation for iOS and found the following example:

// May return nil if a tracker has not yet been initialized with a property ID.
id tracker = [[GAI sharedInstance] defaultTracker];

// Set the custom dimension value on the tracker using its index.
[tracker set:[GAIFields customDimensionForIndex:1]
       value:@"Premium user"]

[tracker set:kGAIScreenName
       value:@"Home screen"];

// Send the custom dimension value with a screen view.
// Note that the value only needs to be sent once, so it is set on the Map,
// not the tracker.
[tracker send:[[[GAIDictionaryBuilder createAppView] set:@"premium"
                                                  forKey:[GAIFields customDimensionForIndex:1]] build]];

But when the dimension is created in control panel, the proposed code is:

NSString *dimensionValue = @"SOME_DIMENSION_VALUE";
[tracker set:[GAIFields customDimensionForIndex:1] value:dimensionValue];

I've been also reading the documentation for Android and found this example:

// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER);
t.setScreen("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.AppViewBuilder()
    .setCustomDimension(1, "premiumUser")
    .build()
);

My questions:

  • Which is the correct way to set dimensions in iOS?
  • In case of the first one (documentation one), why in iOS we need to set the value both in tracker and builder?
  • Why in iOS the dimension value in tracker ("Premium user") is set to a different value in builder ("premium")?
  • Would it be correct to set the same value in tracker and in builder?
  • In that case, why setting it twice? I've tried to set it just in builder and then it chrashes with error this class is not key value coding-compliant for the key &cd1. Setting it in tracker will not repport the value (GA for iOS and custom dimensions).

The code could be:

[tracker set:[GAIFields customDimensionForIndex:1]
       value:@"custom dimension value"]

[tracker send:[[[GAIDictionaryBuilder createAppView] set:@"custom dimension value"
                                                  forKey:[GAIFields customDimensionForIndex:1]] 
like image 230
Miquel Avatar asked Dec 05 '14 13:12

Miquel


1 Answers

There is a good tutorial how to use custom dimensions both iOS and Android and how to set custom reports.

In the case of the first one there are two different ways. They are independent from each other.

First:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:[GAIFields customDimensionForIndex:index] value:@"value"];
tracker send:[[GAIDictionaryBuilder createScreenView] build]];

Second:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[[GAIDictionaryBuilder createScreenView] set:@"value"
                                                     forKey:[GAIFields customDimensionForIndex:index]] build]];

If you want track custom dimensions or custom metric, then you have to create them on the GA adminpage. Here choose custom definitions. After that create a custom report on the customization tab, which will represent your measurements.

Important that you have to wait maybe one or two days after the google analytics registration until measurements will appear in your custom reports.

like image 61
Ádám Gergely Avatar answered Oct 13 '22 00:10

Ádám Gergely