Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics for iOS SDK 2.0 - What to do with "tracker" variable in app delegate?

After following the overview found here:

https://developers.google.com/analytics/devguides/collection/ios/v2/

I am seeing an Unused variable "tracker" warning on the last line of the code added to:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Here's the code from Google's overview page:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Optional: automatically track uncaught exceptions with 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.
  id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];

}

tracker truly sees absolutely no use past this point and the overview document doesn't really say what to do with it. Any suggestions?

like image 432
martin's Avatar asked Nov 18 '12 00:11

martin's


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.

What is Google Analytics on Iphone?

Google Analytics automatically collects certain data and offers optional features that determine which additional types of data are collected and how they are used. An app instance id is automatically assigned to each instance of an app, for purposes of computing user metrics throughout Analytics.


1 Answers

If you don't need a reference to your tracker (and it looks like you don't) you can remove the warning by changing the last line of code from

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

to

[[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];

A use case for keeping a reference to the tracker in this block of code could be if you wanted to create an event for when a user starts the application, without having to call [GAI sharedInstance] to get that reference.

like image 62
rickerbh Avatar answered Oct 30 '22 12:10

rickerbh