8

Wonder if anyone can help me, I am trying to set up Google Analytics on my IOS project. I just need a very simple implementation to show the amount of times a view is being loaded. I followed the google docs (https://developers.google.com/analytics/devguides/collection/ios/v3/) however nothing updated in my dashboard

I have a property set up which is reporting no users

My appdelegate is as follows

#import <UIKit/UIKit.h>
#import "GAI.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property(nonatomic, strong) id<GAITracker> tracker;

@end

my .m contains - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[GAI sharedInstance].trackUncaughtExceptions = YES;

// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;

// Optional: set Logger to VERBOSE for debug information.
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];

// Initialize tracker. which i have set up at the top of my .mn
   self.tracker =  [[GAI sharedInstance] trackerWithTrackingId:kTrackingId];

return YES;
}

And the page that I am trying to record metrics on imports #import "GAI.h" #import "GAIDictionaryBuilder.h"

and contains the following method

-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];


id tracker = [[GAI sharedInstance] defaultTracker];

// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:@"&cd"
       value:@"Home Screen"];

// manual screen tracking
[tracker send:[[GAIDictionaryBuilder createAppView] build]];
}

I am not seeing any errors, I get an initial console log of

NFO: GoogleAnalytics 3.02 -[GAIReachabilityChecker reachabilityFlagsChanged:] (GAIReachabilityChecker.m:159): Reachability flags update: 0X000002

But I just get nothing in the dash board

I also tried the Auto method stated on (https://developers.google.com/analytics/devguides/collection/ios/v3/screens) however this complained of no screen name being present

It's driving me nuts! Any help would be appreciated!

UPDATE

Using the example included in the SDK, I was able to get the initial load to register with google - note this is different from the google documentation :

Appdelegate

 NSDictionary *appDefaults = @{kAllowTracking: @(YES)};
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
// User must be able to opt out of tracking
[GAI sharedInstance].optOut =
![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking];
// Initialize Google Analytics with a 120-second dispatch interval. There is a
// tradeoff between battery usage and timely dispatch.
[GAI sharedInstance].dispatchInterval = 120;
[GAI sharedInstance].trackUncaughtExceptions = YES;
self.tracker = [[GAI sharedInstance] trackerWithName:@"ios app name"
                                          trackingId:kTrackingId];

I used the auto screen tracking for the initial view controller as per google docs, this however only works on the initial loaded view controller, subsequent views using the same method do not register.

Also my problem now is that the APPdelegate method only seems to work in "application didFinishLaunchingWithOptions" which will only work if the app quits each time, putting the same code in 'applicationWillEnterForeground' doesn't work - so frustrating - also tried

    self.tracker = [[GAI sharedInstance] defaultTracker];
[self.tracker set:kGAISessionControl
       value:@"start"];

which seems to have no effect either

user499846
  • 809
  • 3
  • 11
  • 23
  • since I am having nearly the same issues like you I am very interested in your progress - did you find a solution so far?in my app I see that the hits were successfully dispatched, however no screenviews are visible in the Google Analytics Dashboard.. – hreimer Oct 31 '13 at 10:13
  • Hey, I didn't have any success, I ended up just reverting to V2 of the API, really great stats when it works, but it has to be said the documentation was not fantastic given the example in the SDK doesn't use the code ... – user499846 Oct 31 '13 at 22:19
  • thanks, in the meantime I got my issue resolved by following the answers from this guy http://stackoverflow.com/questions/18381083/kgaiscreenname-of-google-analytics-for-ios-v3-is-undeclared seems kGAIScreenName from GAIFields.h has to be used in order to register the screenViews in the GA dashboard..maybe it is of some use to you – hreimer Nov 04 '13 at 22:32

1 Answers1

0

I think your error happens when setting the pagename:

[tracker set:@"&cd" value:@"Home Screen"];

You need to set the kGAIScreenName in order to make it work. I mean, not @"&cd" but kGAIScreenName :

// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:kGAIScreenName value:@"Home Screen"];

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

I hope this helps

Eva Madrazo
  • 4,723
  • 2
  • 19
  • 31