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