IOS - GANTracker nothing to send

I am trying to install the Google Analytics SDK in an iOS app to track page views and events. Following the documentation provided, I don't seem to be able to track the work at all, and I wonder if anyone can help me? The following information may be relevant - I will try to be as descriptive as I can.

  • I configure all devices with iOS 4.3 and higher.
  • I included GANTracker.h in the project-prefix.pch file and it builds ok

Below is a sample from my appdelegate.m code that is called in the didFinishLaunchingWithOptions method

/* Google Analytics tracking code */ [[GANTracker sharedTracker] setSampleRate:100]; [[GANTracker sharedTracker]setDebug:NO]; [[GANTracker sharedTracker] setDryRun:NO]; [[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-111111-1" dispatchPeriod:kGANDispatchPeriodSec delegate:self]; NSLog(@"Dispatch%@", [[GANTracker sharedTracker] dispatch] ? @"ed Successfully": @" Failed"); NSError *error; if (![[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"iPhone" value:@"iv1" withError:&error]) { NSLog(@"There was an error setting this custom variable\n Description: %@\n", [error localizedDescription]); NSLog(@"Failure reason: %@\n", [error localizedFailureReason]); NSLog(@"May we suggest: %@\n", [error localizedRecoverySuggestion]); } if (![[GANTracker sharedTracker] trackEvent:@"Loading" action:@"App Finished Launching" label:@"appDidFinishLaunchingWithOptions" value:-1 withError:&error]) { NSLog(@"There was an error in tracking events\n Description: %@\n", [error localizedDescription]); NSLog(@"Failure reason: %@\n", [error localizedFailureReason]); NSLog(@"May we suggest: %@\n", [error localizedRecoverySuggestion]); } NSString *pageUrlString = [[NSString stringWithFormat:@"http://ios.organisation.tld/appentrypoint"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; if(![[GANTracker sharedTracker] trackPageview:pageUrlString withError:&error]) { NSLog(@"There was an error in tracking initial app entry\n Description: %@\n", [error localizedDescription]); NSLog(@"Failure reason: %@\n", [error localizedFailureReason]); NSLog(@"May we suggest: %@\n", [error localizedRecoverySuggestion]); } 

In my application view dispatchers, I want to track the pageView and do this:

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSError *trackError; NSString *pageUrlString = [[NSString stringWithFormat:@"/aboutsection"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; if(![[GANTracker sharedTracker] trackPageview:pageUrlString withError:&trackError]) { //Handle error here NSLog(@"There was an error tracking this pageview\n Description: %@\n", [trackError localizedDescription]); NSLog(@"Failure reason: %@\n", [trackError localizedFailureReason]); NSLog(@"May we suggest: %@\n", [trackError localizedRecoverySuggestion]); } } 

Going back to my appdelegate.m I also have the following set of delegates

 - (void)trackerDispatchDidComplete:(GANTracker *)tracker eventsDispatched:(NSUInteger)hitsDispatched eventsFailedDispatch:(NSUInteger)hitsFailedDispatch { NSLog(@"Google analytics dispatch\n Succeeded?:\n %i, \n Failed?: %i", hitsDispatched, hitsFailedDispatch); } 

Does this lead to something like Successful ?: 5 Failed: 0, so failures don't appear there

I also see a log message ... do not send anything. Sign in to Google Analytics. I do not see any visits. Real-time analytics analysis also shows that nothing is happening.

Did I miss something?

+4
source share
1 answer

It only worked when I tried the following steps:

1- on appdelegate.h class #import "GAI.h"

2- when appdelegate in the function "didFinishLaunchingWithOptions" add these codes

  // 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 = NO; // Create tracker instance. [[GAI sharedInstance] trackerWithTrackingId:"your tracking application id from google analytics"]; 

3- in any uiviewcontroller class. h #import "GAI.h"

4- at.h replace this part of ": uiviewcontroller" with ": GAITrackedViewController"

5- at.m add in view uploaded this line

 [[[GAI sharedInstance] defaultTracker] trackView:"your view title"]; 
  • Be careful with point 5, you need to implement it this way, I think the GA library has problems in some other way and in the documentation. I tried and searched a lot about this problem, and by chance it worked that way, next to it was the fastest way to show the effect on the GA screen.

  • Please note: you must create your mobile application in Google Analytics, take care of the application ID to add it. Fix in iOS app.

0
source

Source: https://habr.com/ru/post/1440989/


All Articles