Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to stop the Google Analytics tracker in applicationWillTerminate? (iOS)

I'm using Google Analytics in my app, and while I believe I've carefully followed the getting started guides and screen tracking manuals, I don't see anywhere that I should stop the tracker when the app goes to the background or terminates. I can assume that maybe I don't have to, but I don't want to assume. So, should I? Or does Google Analytics automatically stop when the app goes to the background/terminates? (I also can't find documentation that says so.)

I also ask this because I see from GAITracker.h that there's a method called close. Its description is as follows:

Close the tracker. This will mark it as closed and remove it from the list of trackers accessible through [GAI trackerWithTrackingId:], thus decrementing its reference count (and causing it to be dealloced unless it has been retained by the application). Once this method has been called, it is an error to call any of the tracking methods, and they will not result in the generation of any tracking information to be submitted to Google Analytics.

And since, if I understand correctly, close effectively removes the tracker from memory, does simply calling [[GAI sharedInstance] trackerWithTrackingID:@"MY-TRACKING-ID"] create a new one which I can use when the app is re-launched?

like image 766
MLQ Avatar asked Oct 21 '22 03:10

MLQ


1 Answers

No, there is no need to stop Google analytics tracker for iOS.

Google had added close method in iOS SDK version 2.0beta1(May 25, 2012). But, they had not provided any document or tutorial to use this till date. I have used Google analytics in my two apps to track app installation, screen most visited and some events also. I didn't close(or stop) the tracker anywhere in the app and I guess it's not necessary till now.

We add the following code in application:didFinishLaunchingWithOptions: method.

id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];

The above line creates a new tracker instance everytime as the app launches.
So, I don't think it would be necessary to stop(or close) the tracker as the app terminates.

like image 56
Piyush Avatar answered Oct 24 '22 04:10

Piyush