Google Analytics in iOS (Not Working) Google Analytics in iOS (Not Working) ios ios

Google Analytics in iOS (Not Working)


I had the same problem with 3.01. My problem was actually in the Google Analytics admin section.

I had a profile setup for mobile (which was actually setup as if it were a website) which worked with version 1.x. However it appears that Google has now implented "mobile" profiles as well. I believe that the 3.x mobile SDKs cannot track to "Web" profiles.

Create a new profile by following the instructions here. And then use the new tracking Id and it should start tracking.

Note: Do not set the dispatchInterval to 0, as others have suggested, this also prevented tracking, set it to 1. This fixed everything for me.


UPDATE -- Google Analytics SDK for iOS v3

So I'm using v3, and there is not any problem:

I'm implemented it in the AppDelegate. In .h file:

#import "GAI.h"@property (nonatomic,assign) id<GAITracker> tracker; // I'm not using ARC (assign)

.m:

#import "GAIDictionaryBuilder.h"#import "GAIFields.h"// GOOGLE ANALYTICS[GAI sharedInstance].trackUncaughtExceptions = YES;[GAI sharedInstance].dispatchInterval = 0;tracker = [[GAI sharedInstance] trackerWithTrackingId:@"yourGAID"];

And write a method like this:

- (void) sendGoogleAnalyticsView:(NSString*)viewName{    [tracker set:kGAIScreenName value:viewName];    [tracker send:[[GAIDictionaryBuilder createAppView] build]];    [[GAI sharedInstance] dispatch]; // this will force track your views.}

Old answer:

See this answer below this link, if you do it the same as I told in this answer it must work

Another stack-overflow answered question about google-analytics

and use these methods:

[GAI sharedInstance].optOut = YES;[GAI sharedInstance].dispatchInterval = 0;[GAI sharedInstance].trackUncaughtExceptions = YES;    tracker = [[GAI sharedInstance] trackerWithTrackingId:@"YOUR TRACKERID"];[tracker sendView:@"Your View name"];[tracker sendEventWithCategory:@"YOUR CATEGORY" withAction:@"YOUR ACTION" withLabel:nil withValue:nil];

Download GoogleAnalyticsiOS_2.0beta4.zip from this link this will contain those classes what you need, and it will work perfectly. Be careful, google analytics got a lead time, to show you information, about real time. And not real time datas will show only a day after

EDIT for 3.0:

I found some probably useful things for you:

We have just come across this issue and this is slightly out of date so here is an updated answer. The issue we were having after following the instructions on the Google Analytics website, they instruct you to add the following files GAI.h, GAIDictionaryBuilder.h, GAILogger.h, GAITrackedViewController.h, GAITracker.h and libGoogleAnalytics_debug.a library. What they completely forget to include on the website instructions is the one where you have to include libGoogleAnalyticsServices.a library. This is included in the zipped download but there is no instructions to indicate to include this in the debug version.

Note : In the readme.txt libGoogleAnalyticsServices.a is just referred to as libGoogleAnalytics.a Google have failed to update their documentation to include the new name or the correct instructions that indicate this is required in debug.

Files and Libraries that most be included

GAI.hGAIDictionaryBuilder.hGAIFields.hGAILogger.hGAITrackedViewController.hGAITracker.hlibGoogleAnalytics.a // Also know as libGoogleAnalyticsServices.alibGoogleAnalytics_debug.a

enter image description here

plus information:

I'm pretty sure google has not yet provided a arm64 version of their libGoogleAnalyticsServices.a, which is really annoying ...it has been weeks since the public the release of Xcode 5GM.

For now, I guess only build for armv7, armv7s or remove google analytics until they get their head out of their pants.

Here is a iOS Getting Started Guide. for implement it.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  // 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 = 0;  // Optional: set Logger to VERBOSE for debug information.  [[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];  // Initialize tracker.  id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-Y"];}

To manually send a screen view, set the screen field values on the tracker, then send the hit:

// May return nil if a tracker has not already been initialized with a// property ID.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:kGAIScreenName       value:@"Home Screen"];[tracker send:[[GAIDictionaryBuilder createAppView] build]];

Or Automatic Screen Measurement:

Automatically measure views as screens using the GAITrackedViewController class. Have each of your view controllers extend GAITrackedViewController and add a property called screenName. This property will be used to set the screen name field.

//// MyViewController.h// An example of using automatic screen tracking in a ViewController.//#import "GAITrackedViewController.h"// Extend the provided GAITrackedViewController for automatic screen// measurement.@interface AboutViewController : GAITrackedViewController@end//// MyViewController.m//#import "MyViewController.h"#import "AppDelegate.h"@implementation MyViewController- (void)viewDidLoad {    [super viewDidLoad];    // Set screen name.    self.screenName = @"Home Screen";}// Rest of the ViewController implementation.@end

Event tracking:

link

To send an event to Google Analytics, use GAIDictionaryBuilder.createEventWithCategory:action:label:value: and send the hit, as in this example:

// May return nil if a tracker has not already been initialized with a property// ID.id<GAITracker> = [[GAI sharedInstance] defaultTracker];[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"     // Event category (required)                                                      action:@"button_press"  // Event action (required)                                                       label:@"play"          // Event label                                                       value:nil] build]];    // Event value


In the AppDElegate.m file :

#import "AppDelegate.h"#import "GAI.h"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   [GAI sharedInstance].trackUncaughtExceptions  = YES;   [GAI sharedInstance].dispatchInterval = 1;   [[[GAI sharedInstance] logger]setLogLevel:kGAILogLevelVerbose];   id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"TrackingId"];   [GAI sharedInstance].defaultTracker = tracker;   return YES;}

In ViewController.h

#import <UIKit/UIKit.h>#import "GAITrackedViewController.h"@interface FirstViewController : GAITrackedViewController@end

In ViewController.m

- (void)viewDidLoad {    [super viewDidLoad];    self.screenName = @"RED Screen";}

Try it. This worked for me just fine. I tried it more than three apps. And All are working for realtime. If your account for your app is new then you might have to wait for 24h or more to see the result. Sometimes it take time to display realtime data without any reason.

Sometimes it also does not work because of old Google Analytics sdk. To get the latest sdk you can use cocoa pod. here is the procedure :

platform :ios, '10.0'target “GoogleAnalyticsTestApp” do   pod 'GoogleAnalytics'end

Write these lines in your pod file in your project directory and save it. then install pod. To know how to install cocoa pod see the link :

Error importing Google Analytics iOS SDK using Cocoa Pods

Do not write Google/Analytics. Write GoogleAnalytics. Hope it will solve the problem.