How to use custom variables in Google Analytics for iOS

July 30
blog author

Appno Blogger

Appnovation Coop

Google announced the addition of custom variables to the Mobile Analytics SDK for mobile applications in December 2010. Previously, Google Analytics for mobile applications only could track Pageviews, Events and E-Commerce. Now we can track how and why users interact with pages and events.

Let me explain with an example.

Before using custom variables, Google Analytics SDK for iOS needs to be installed. http://code.google.com/mobile/analytics/download.html#Google_Analytics_SDK_for_iOS After starting GANtracker, custom variables should be set. For example, user id is set to track each user's activities in the app. //start tracker [[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-0000000-1" dispatchPeriod:kGANDispatchPeriodSec delegate:nil]; // Set custom variables if (![[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"userID" value:@"user_id" withError:&error]) { // Handle error here } After setting up custom variables, you can put tracking code for viewing pages or events. if (![[GANTracker sharedTracker] trackEvent:@"my_category" action:@"my_action" label:@"my_label" value:-1 withError:&error]) { // Handle error here } if (![[GANTracker sharedTracker] trackPageview:@"/app_entry_point" withError:&error]) { // Handle error here }

Next, you need to access Google Analytics and create a new custom report. In Custom reporting menu, create a new custom report by dragging Metrics and Dimensions in the sections. In visitors menu, you need to drag custom variable (key) to dimensions and drag custom variables (value) to sub dimension. If you open "Preview report", you will see user section with user ids. For viewing individual user activities, you need to create a new custom segment in Advanced Segments menu by dragging custom variables (key or value). In conclusion, custom variables in Google Analytics work pretty well on iOS application. Please do not hesitate to use custom variables to track users activities.