Google Analytics on iOS returns NO on submit, no debug output

When I tried to implement the Google Analytics SDK for iOS, I ran into two brick walls.

The first is that after executing this code in application:DidFinishLaunchingWithOptions:

 [[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-XXXXXXX-YY" dispatchPeriod:10 delegate:self]; [[GANTracker sharedTracker] setDebug:YES]; 

.. and then try to track something or call dispatch , no debug messages are logged at all. I added NSLog lines before and after call tracking, and the code is definitely reached.

Secondly, when I try to send manually, it returns NO . All the other problems that I have seen on the Internet is where dispatch returns YES , but it somehow does not work properly. What if dispatch really returns NO ?

I tried adding an NSError * reference to the track methods, and those that actually succeed (no errors, the function returns YES ). But events, of course, are not sent periodically, since we no longer see anything on the GA account in more than 24 hours.

EDIT: I also have NSLog calls in both delegate methods ( hitDispatched: and trackerDispatchDidComplete:eventsDispatched:eventsFailedDispatch: , and none of them are called.

+6
source share
6 answers

cough

I made a mistake #define to run the tracker object in my application. Other files were written correctly, so logging instructions appeared, but when I tried to log in immediately before starting the tracker, it did not appear.

Unfortunately. Well, at least there's a decent troubleshooting post for Google Analytics on SO!

0
source

I think you should check this to delegate the GANTracker method.

 - (void)trackerDispatchDidComplete:(GANTracker *)tracker eventsDispatched:(NSUInteger)hitsDispatched eventsFailedDispatch:(NSUInteger)hitsFailedDispatch{ //print or check number of events failed or success } 
+1
source
 //Delegate is set to 'nil' instead of class instance which implements the delegate methods. [[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-XXXXXXX-YY" dispatchPeriod:10 delegate:nil]; 

In your case, assuming that UIApplicationDelegate can implement GANTrackerDelegate , calling the message should set the delegate as 'self' .

Hurrah!!
Amar.

+1
source

The sending may be related to the start thread of the calling thread. Is it possible that you are launching this from a secondary thread, which may not exist by the time the sending sends you back?

+1
source

You didn't turn on dryRun, did you? Double check:

 [[GANTracker sharedTracker] setDryRun:NO]; 

Also try dispatchSynchronous, it will block when it is sent, but it can help if things are not in the same threads:

 [[GANTracker sharedTracker] dispatchSynchronous]; 
+1
source

Just've checked it from scratch, debugged fine

a) your device is somehow different (I still had unresolved crashes on Apple tester's specific iPad 3 unresolved, so that would not be a huge surprise)

b) your code is somehow different - and it is much easier for you to fix it.


For a) there is no advice, but to test it on all the devices that you could get, for b) I could only say what worked for me:

  • download 1.4 sdk here
  • got google sample projects git clone https://code.google.com/p/google-mobile-dev.analytics-end-to-end/
  • final / Analytics configured Example to run, source changed slightly

(trackEvent ::: were called from an example, the application rebooted manually, since there is a zero period of time requiring a dispatch call)

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[GANTracker sharedTracker] startTrackerWithAccountID:kGANAccountId dispatchPeriod:0 delegate:self]; NSLog(@"Dispatch%@", [[GANTracker sharedTracker] dispatch] ? @"ed Successfully": @" Failed"); [self.window addSubview:tabBarController.view]; [self.window makeKeyAndVisible]; return YES; } 

That he, the magazine says Dispatched Successfully , is worth a try, I think.

+1
source

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


All Articles