42

Today, I found GoogleAnalytics-iOS-SDK have new 3.0 version in Cocoapods. I upgraded and I try to modified the code of manual screen measurement as below:

id tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"Detail View"];
[tracker send:[[GAIDictionaryBuilder createAppView] build]];

However, I always get error about kGAIScreenName is undeclared. Even I add GAIFields.h header, it still not work.

What did I miss?

rmaddy
  • 298,130
  • 40
  • 468
  • 517
derjohng
  • 857
  • 2
  • 9
  • 18

2 Answers2

90

You have to include two more things:

#import "GAIDictionaryBuilder.h"
#import "GAIFields.h"

Checking what's in GAIFields.h I can see that kGAIScreenName is there:

extern NSString *const kGAIScreenName;   // synonym for kGAIDescription

Might be important point that the current Google Analytics is in beta, so using the latest downloadable SDK is always a good idea. What I tried and what is working currently for me is Version: 3.0 (August 16, 2013).

nzs
  • 3,232
  • 15
  • 22
  • Thanks. I exactly added GAIFields.h, and I used to use Cocoapods to manage the GA library instead of downloadable SDK. Now, I downgrade back to 2.0beta4. I will use this, until experts fix it. ^^ – derjohng Aug 30 '13 at 16:32
  • I also experienced different problems with new Google Analytics SDK: for me using the screenName setting does not work in viewDidAppeare, it is not reporting the screen usage towards Google. I managed to have a solution for this particular problem, so if you need more help, just comment here. – nzs Aug 31 '13 at 20:28
  • @codedad as I am facing that same problem and wondering why the screenName won't get sent to Google I am quite curious about your solution - would you mind posting it? thanks a lot – hreimer Oct 31 '13 at 12:16
  • seems my issue wasn't all that different to your answer and got resolved by it..thanks – hreimer Oct 31 '13 at 13:46
  • @hajn: glad to hear it is resolved now. If you need my solution to screenName issue lately here it is: I had to use lower level SDK call. id tracker = [[GAI sharedInstance] defaultTracker]; [tracker set:kGAIScreenName value:@"CardsView"]; [tracker send:[[GAIDictionaryBuilder createAppView] build]]; – nzs Oct 31 '13 at 15:41
  • i wasated 2 hours and then fine this solution. :) +1 – Nirav Jain Jun 09 '15 at 12:17
0

I am using a hardcoded value of @"&cd" for kGAIScreenName and it works perfectly. Found the value in the Measurement Protocol documentation at Google https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#apptracking

Adrian Spinei
  • 570
  • 5
  • 15