Will Google Analytics not track iOS browsing?

I added the latest Google Analytics SDK to the iOS app (beta 2.0). I did the same as the manual and added this code to the application delegate:

// Optional: automatically send uncaught exceptions to Google Analytics. [GAI sharedInstance].trackUncaughtExceptions = YES; // Optional: set Google Analytics dispatch interval to eg 20 seconds. [GAI sharedInstance].dispatchInterval = 20; // Optional: set debug to YES for extra debugging information. [GAI sharedInstance].debug = YES; // Create tracker instance. self.tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-TRACKINGID-2"];//UA-33873963-13 - My testing google analytics trackingId [self.tracker setSessionStart:YES]; [self.tracker setSessionTimeout:60]; 

Now, in each view, I have added the following:

 self.trackedViewName = @"Main Menu Screen"; 

Everything works fine, but for some reason 3 out of 20 screens do not go to Google, and I don’t know why. I searched the entire network, but no one came across this problem. I thought that if someone is familiar with this problem, it will be full of the stack.

Please help me. Thanks!

+6
source share
6 answers

The problem was fixed in the simplest way.

The code I wrote is for AppDelegate . After the tracker has been initialized once with the tracking identifier, you just need to call it in every view that you use. (I'm not sure about this, but it worked for me anyway.)

So in AppDelegate :

 // Optional: automatically send uncaught exceptions to Google Analytics. [GAI sharedInstance].trackUncaughtExceptions = YES; // Optional: set Google Analytics dispatch interval to eg 20 seconds. [GAI sharedInstance].dispatchInterval = 20; // Optional: set debug to YES for extra debugging information. [GAI sharedInstance].debug = YES; // Create tracker instance. self.tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-TRACKINGID-2"];//UA-33873963-13 - My testing google analytics trackingId [self.tracker setSessionStart:YES]; [self.tracker setSessionTimeout:60]; 

Inside viewDidLoad view viewDidLoad :

 [GAI sharedInstance] defaultTracker]; [self.tracker sendView:@"Some name"]; 

After that, it worked great.

+4
source

I had the same problem a while ago. I bet you don't call the following methods in your overrides:

  • [super viewDidLoad] in your -(void)viewDidLoad override
  • [super viewDidAppear:animated] to -(void)viewDidAppear:(BOOL)animated override
  • [super viewDidUnload] in -(void)viewDidUnload override
  • ... (take care of all the other methods that you override from the GAITrackedViewController

Specifically, your methods should look like this:

 -(void)viewDidLoad { // call this at the beginning of the overridden methods self.screenName = @"Some Name"; [super viewDidLoad]; // your remaining code here } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // your remaining code here } 

The most important methods are viewDidLoad and viewDidAppear: since specifically for real-time viewDidAppear: , viewDidAppear: shows that this view is currently visible.

EDIT: Starting with version 3.0 of the Google Analytics SDK, the screenName property must be set before calling the viewDidLoad super method.

+19
source

I am using version 3.02 and encountered the same problem. The following fixed issue:

 -(void) viewDidAppear:(BOOL)animated { self.screenName = @"My Screen"; // set screenName prior to calling super [super viewDidAppear:animated]; ... } 

You definitely want to call super because it causes the sending of ga data. It seems to me that screenName needs to be set in front of it.

+15
source

So, I found the answer to this question:

In the header add this: #import "GAI.h"

Now in viewDidLoad:

  • Add self.trackedViewName = @"Some Name";

  • How to do it: [GAI sharedInstance] defaultTracker];

  • Also add: [self.tracker sendView:@"Some Name"];

Than it will work fine.

+2
source

So .. This is for noobies there .. (including me) ..

It may be stupid to think about, but for me a dumb view appeared super [super viewDidAppear: animated]; after a call to set the screen name.

As an aside, I'm just an iOS user, but when I looked in gaitrackedviewcontroller.h, the last screen name to install is, well, screenname not trackedviewname. So this is what mine looked like this:

  • (void) viewDidAppear: (BOOL) animated {

    self.screenName = @ "Login screen";

    [super viewDidAppear: animated];

}

Good luck. Hope this helps anyone. Stay cool.

0
source

In environment 3.10 , I had a similar problem. I tried another guy, but I do not hope. Finally, I found that ANSWER is outside the official guidelines.

After adding two lines it works.

  NSDictionary *appDefaults = @{kAllowTracking: @(YES)}; [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; 

The official instructions do not mention that we need the kAllowTraking register by default.

0
source

All Articles