Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics for iOS - Sending Custom Event Data using Dictionaries as createEventWithCategory allows only 4 parameters to be sent

I decided to use Google Analytics over Flurry, as Flurry stopped updating tracking Events and nobody from Flurry Support team replied to my query. My requirement is as follows:

  • "Whenever user clicks on tab I need to create an event which includes Tab Name, User ID, Time Stamp." A screenshot from Flurry Event log may describe it more clearly.

Flurry Event Log

So, in Google Analytics Event Tracking function createEventWithCategory almost does the needful but it does not allow me to add my custom parameters like User ID, Time Stamp.

[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"     // Event category (required)
                                                  action:@"button_press"  // Event action (required)
                                                   label:@"play"          // Event label
                                                   value:nil] build]];    // Event value

I tried for two solutions and neither of them are upto my expectation which brings me with two questions regarding each approach I took:

Attempt 1: Custom Dimensions:

Documentation has a sample code like this :

// 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]];

[Custom dimension values can be sent with any Google Analytics hit type, including screen views, events, ecommerce transactions, user timings, and social interactions.]

So, I decided to use custom dimensions with createEventWithCategory method and ended up doing like as follows **which works but does not show data as Flurry showed. **

 NSString *dimensionValue = @"USER_ID";
[tracker set:[GAIFields customDimensionForIndex:1] value:dimensionValue];
[tracker send:[[[GAIDictionaryBuilder createEventWithCategory:@"TAB_CLICK"
                                                           action:@"Tab Hit"
                                                            label:clickedTabName
                                                            value:nil]
              set:currentUserEmail forKey:[GAIFields customDimensionForIndex:1]] build]];

GA Custom Dimension


Attempt 2: Setting and Sending Data using Dictionaries:

I followed the documentation and tried sending NSDictionary object to - (void)send:(NSDictionary *)parameters;method declared in GAITracker.h.

But I have no clue where this data will appear in dashboard. Neither in Behavior not in Real Time it shows any update.

 id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-X"]; 
 NSDictionary *dataToSendGoogleAnalytics = [NSDictionary dictionaryWithObjectsAndKeys:currentTime,@"TIME_STAMP",clickedTabName,@"TAB_NAME", currentUserEmail, @"USER_ID",nil];   
 [tracker send:dataToSendGoogleAnalytics];

Question: Can't I use something straightforward as Flurry which will give me result like in image and allow me to have event parameters like USER_EMAIL, Time_Stamp, TAB_NAME altogether with every event?:

Flurry Event

Using simple function like this which accepts NSDictionary object?

[Flurry logEvent:@"TAB_CLICKED" withParameters:dataToSendFlurry timed:YES];

Any suggestions or hint would be appreciated. Thank you.

like image 343
rohan-patel Avatar asked Jun 11 '14 21:06

rohan-patel


1 Answers

you can send custom data to google analytics by using custom dimension.

you need to add custom dimension from your dashboard after adding that you will get the code..

Just integrate that in your project and follow below link to see the values.

http://www.lunametrics.com/blog/2013/09/10/access-custom-dimensions-google-analytics/#sr=g&m=o&cp=or&ct=-tmc&st=hpphmf%20dvtupn%20ejnfotjpo&ts=1384845402 enter image description here

like image 193
Suhas Arvind Patil Avatar answered Oct 18 '22 23:10

Suhas Arvind Patil