Hi Am trying to integrate google analytics in my iOS app. But its not working,when i open the dashbord of analytics its showing real time users 0 ,actually it always showing this zero .
following are the steps i have done so far
1.Downloaded the , Google Analytics SDK for iOS.
then i just followed this developer.google.com link link
these are my codes.
in appdelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//analytics
// Optional: automatically send uncaught exceptions to Google Analytics.
[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.
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-********-*"];
return YES;
}
in my viewcontroller.h file
#import "GAITrackedViewController.h"
#import <UIKit/UIKit.h>
@interface TopNewsViewController : GAITrackedViewController{
}
@property(nonatomic,retain)NSString *screenName;
@end
in my viewcontroller.m
#import "GAIDictionaryBuilder.h"
#import "GAI.h"
#define kGAIScreenName @"TopNewsViewController"
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
id tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName
value:@"Home Screen"];
[tracker send:[[GAIDictionaryBuilder createAppView] build]];
}
Following is printing in my log
2014-01-16 19:39:56.766 tempfiles12[844:60b] <Google> To get test ads on this device, call: request.testDevices = [NSArray arrayWithObjects:@"12d2c8c8808caa10aa1f6d947afc7f33", nil];
2014-01-16 19:39:57.555 tempfiles12[844:60b] INFO: GoogleAnalytics 3.02 -[GAIReachabilityChecker reachabilityFlagsChanged:] (GAIReachabilityChecker.m:159): Reachability flags update: 0X000002
2014-01-16 19:39:57.563 tempfiles12[844:1803] ERROR: unable to get the receiver data from the DB!
2014-01-16 19:39:57.571 tempfiles12[844:60b] INFO: GoogleAnalytics 3.02 -[GAITrackedViewController viewDidAppear:] (GAITrackedViewController.m:21): Tracked view controller missing view name.
2014-01-16 19:39:57.611 tempfiles12[844:5317] VERBOSE: GoogleAnalytics 3.02 -[GAIBatchingDispatcher persist:] (GAIBatchingDispatcher.m:414): Saved hit: {
parameters = {
"&_u" = ".o-etnoK-L";
"&_v" = "mi3.0.2";
"&an" = tempfiles12;
"&av" = "6.0";
"&cid" = "b34bfd7f-45f8-4f4e-84a5-a0d0988e7356";
"&sr" = 768x1024;
"&t" = appview;
"&tid" = "UA-47216473-1";
"&ul" = en;
"&v" = 1;
"&z" = 4061780796142886022;
TopNewsViewController = "Home Screen";
gaiVersion = "3.02";
};
timestamp = "2014-01-16 14:09:57 +0000";
}
2014-01-16 19:40:17.009 tempfiles12[844:5317] VERBOSE: GoogleAnalytics 3.02 -[GAIRequestBuilder requestGetUrl:payload:] (GAIRequestBuilder.m:177): building URLRequest for https://ssl.google-analytics.com/collect
2014-01-16 19:40:17.011 tempfiles12[844:5317] VERBOSE: GoogleAnalytics 3.02 -[GAIBatchingDispatcher dispatch] (GAIBatchingDispatcher.m:499): Sending hit(s) GET: https://ssl.google-analytics.com/collect?_v=mi3.0.2&av=6.0&_u=.o-etnoK-L&ul=en&v=1&an=tempfiles12&t=appview&sr=768x1024&cid=b34bfd7f-45f8-4f4e-84a5-a0d0988e7356&tid=UA-47216473-1&ht=1389881397577&qt=19431&z=4061780796142886022
2014-01-16 19:40:17.232 tempfiles12[844:60b] INFO: GoogleAnalytics 3.02 -[GAIBatchingDispatcher didSendHits:response:data:error:] (GAIBatchingDispatcher.m:157): Hit(s) dispatched: HTTP status 200
2014-01-16 19:40:17.233 tempfiles12[844:5317] INFO: GoogleAnalytics 3.02 -[GAIBatchingDispatcher deleteHits:] (GAIBatchingDispatcher.m:426): hit(s) Successfully dispatched
2014-01-16 19:40:17.240 tempfiles12[844:5317] INFO: GoogleAnalytics 3.02 -[GAIBatchingDispatcher didSendHits:] (GAIBatchingDispatcher.m:167): 1 hit(s) sent
DashBoard
Another reason if it's doesn't work : You have to wait 24-48h after creating google tracking ID to see results. (Even for real time)
See also : Google Analytics on iOS: events not tracked
Wow..I found the answer..
in our viewcontroller.m file
we need to use the screen name variable already defined in GAITrackedViewController.m
so in my case the variable name was "screenname" and what i have done is i declare same variable in my viewcontroller.h .
So i removed that line and i added this line
"self.screenname=@"my screen name";
NOw its working..
rest of the things are working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With