Alexander Gattringer
Alexander Gattringer

Reputation: 175

Google Analytics: tracking a custom dimension on iOS?

I have some problems regarding custom dimensions with Google Analytics on iOS. I already set up my custom dimension in the web interface of GA. But if I send my custom dimension in the AppDelegate on initialization of the GA tracker it doesn't show up like expected.

id tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:[GAIFields customDimensionForIndex:1] value:@"testValue"];
[tracker send:[[[GAIDictionaryBuilder createAppView] set:@"testValue" forKey:[GAIFields customDimensionForIndex:1]] build]];

Does anybody experience similar problems?

Upvotes: 0

Views: 408

Answers (2)

Alexander Gattringer
Alexander Gattringer

Reputation: 175

I found out that the "problem" wasn't really one. I did set up everything correctly. But Google Analytics needs some time to evaluate the data. It takes really long (48hrs+) before it shows up in the web interface. So for everyone experiencing similar problems: be patient!

Upvotes: 0

Sandy Patel
Sandy Patel

Reputation: 768

> I hope it's help you.
// Call this on didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self startGoogleAnalyticsTracking];
    [self performSelector:@selector(sendGoogleAnalyticsStartup)     withObject:nil afterDelay:3];
       // --------- Enter your code here
----------//
return YES;
}

- (void)startGoogleAnalyticsTracking {
    @try {
//        self.googleAnalyticsTracker = [[GAI sharedInstance] trackerWithTrackingId:”PASTE YOUR TRACKING ID HERE”];
        // Optional: automatically send uncaught exceptions to Google Analytics.
        [GAI sharedInstance].trackUncaughtExceptions = YES;
        // Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
        [GAI sharedInstance].dispatchInterval = 10;
        // Optional: set debug to YES for extra debugging information.
        [GAI sharedInstance].debug = YES;

        // **** REPLACE Tracking Id with your own GA Tracking Id **** //
        // Create tracker instance.Tracking Id
        id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"Tracking Id"];
        [tracker sendView:@"Application Loaded"];
    }@catch (NSException *exception) {
        NSLog(@"exception:%@",exception);
    }
}



- (void)sendGoogleAnalyticsStartup {
        @try {
            [self.googleAnalyticsTracker sendEventWithCategory:@"Application Events" withAction:nil withLabel:@"Tracking Starts" withValue:nil];
        }@catch (NSException *exception) {
            NSLog(@"exception=%@",exception);
        }
    }


 - (void)stopGoogleAnalyticsTracking {
        @try {
            [self.googleAnalyticsTracker sendEventWithCategory:@"Application Events" withAction:nil withLabel:@"Tracking Suspended /Stopped" withValue:nil];
        }@catch (NSException *exception) {
            NSLog(@"exception=%@",exception);
        }
    }

Upvotes: 1

Related Questions