Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics won't track a view on iOS?

I've added the newest Google Analytics SDK to my iOS application (version 2.0 beta 4). I did the same as the guide says and added this code to app delegate:

// 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 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, on each view I've added this:

self.trackedViewName = @"Main Menu Screen";

Everything works fine, but for some reason 3 out of the 20 screens is not sending themselves to Google and I don't have a clue why. I've searched all over the net, but no one has came across this issue. I figured that if someone familiar with this issue, it's on stack-overflow.

Please help me. Thanks!

like image 784
ytpm Avatar asked Feb 19 '13 08:02

ytpm


People also ask

Can Google Analytics track iOS?

For install tracking on iOS, Google Analytics relies on Apple's resettable Identifier for Advertising (IDFA) to match app sessions to campaigns. To accomplish this, Google Analytics relies on Ad Networks to provide and send the IDFA and other campaign information to Google Analytics when an app user clicks on an ad.

Why isn't my Google Analytics showing any data?

You've turned on the User-ID feature in your view settings but haven't configured it. User-ID tracking needs an additional code implementation and if it's not done, your Google Analytics view will contain no data.

Does iOS 14 block Google Analytics?

As more information has surfaced, it appears that Intelligent Tracking Prevention (ITP) in Safari 14 is not completely blocking Google Analytics. Instead, it's blocking third-party tracking cookies and cross-site scripting requests, which limits portions of Google Analytics.

What you Cannot track with Google Analytics?

You can't track Individual users Unfortunately, Google Analytics only allows to use a unique user ID and prohibits sending personal information, username or an IP address. So you can't really see and understand how specific users behave on your site and get valuable data.


2 Answers

I had the same problem some time ago. I bet that you don't call the following methods in your overrides:

  1. [super viewDidLoad] in your -(void)viewDidLoad override
  2. [super viewDidAppear:animated] in your -(void)viewDidAppear:(BOOL)animated override
  3. [super viewDidUnload] in your -(void)viewDidUnload override
  4. ... (take care of all the other methods that you are overriding from GAITrackedViewController

Concretely, your methods should look like the following:

-(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 especially for real time tracking the viewDidAppear: shows that this view is currently visible.

EDIT: Since version 3.0 of the Google Analytics SDK the screenName property should be set before calling the viewDidLoad method of super.

like image 154
who9vy Avatar answered Oct 02 '22 23:10

who9vy


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

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

   ...
}

You definitely want to to call super because it triggers sending the ga data. It appears to me that the screenName needs to be set prior to it.

like image 32
Sean Avatar answered Oct 02 '22 23:10

Sean