0

I am new to Google Analytics. In my project i have to send multiple dimensions for an event. Actually i need to raise an event with two dimensions, event raises twice because i am raising the event individually for each dimension. I googled for multiple dimensions and i found this, here i'm lil confused to convert it in to iOS (i mean in Objective-C). Here is my code which i call for each dimension.

[tracker send:[[[GAIDictionaryBuilder createEventWithCategory:[eventDict valueForKey:@"category"]
                                                           action:[eventDict valueForKey:@"action"]
                                                            label:[eventDict valueForKey:@"label"]
                                                            value:[eventDict valueForKey:@"value"]]
                    set:nameStr forKey:[GAIFields customDimensionForIndex:indexval]] build]];

Please suggest me a best solution for mutiple dimensions for an event.

1
  • Try this code. It works for me. [[GAI sharedInstance].defaultTracker trackEventWithCategory:@"UIAction" withAction:@"buttonLoginPress" withLabel:@"Next button to home page" withValue:[NSNumber numberWithInt:0]]; Commented May 20, 2016 at 5:10

1 Answer 1

3

Try this solution this will help you, this solution worked for me.

Note - You need to set it to tracker,google analytics framework internally it sends the data that is send to the tracker. You can check by printing the logs.

For Screen Views you can do this.

 + (void)trackScreenStatusScreenName:(NSString *)screenName 
    {
        id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
        [tracker set:kGAIScreenName value:screenName];

        NSString * userStages = @"Some string";//dimension for user stages
        NSString * userID = @"Some user ID";
        NSString * contentStages = @"Some stage";

       [tracker set:[GAIFields customDimensionForIndex:1]
                      value:userID];
       [tracker set:[GAIFields customDimensionForIndex:2]
                          value:userStages];

       [tracker set:[GAIFields customDimensionForIndex:3] value:contentStages];

       [tracker send:[[GAIDictionaryBuilder createScreenView] build]];

    }

For event you can do this

+ (void)createEventWithCategory:(NSString *)eventCategory action:(NSString *)action label:(NSString *)label value:(NSNumber *)value
{
    id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

    NSString * userStages = @"Some string";//dimension for user stages
            NSString * userID = @"Some user ID";
            NSString * contentStages = @"Some stage";

           [tracker set:[GAIFields customDimensionForIndex:1]
                          value:userID];
           [tracker set:[GAIFields customDimensionForIndex:2]
                              value:userStages];
           [tracker set:[GAIFields customDimensionForIndex:3] value:contentStages];

    [tracker send:[[GAIDictionaryBuilder createEventWithCategory:eventCategory
                                                          action:action
                                                           label:label
                                                           value:value] build]];
}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.