Implementing Google Analytics for iOS

How can someone with experience with Flurry Analytics someone explain the correct location to track events and custom variables in Google Analytics for iOS? The example that Google provides all contributes to the AppDelegate. Not sure if they did it for the sake of brevity or not.

I understand why the init call goes to AppDelegate:

//AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {

   [[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-0000000-1"
                                    dispatchPeriod:kGANDispatchPeriodSec
                                          delegate:nil];

   //...

}

      

But what about these calls, which collect specific data related to a specific species? Can they go into their respective ViewControllers instead of AppDelegate?

[[GANTracker sharedTracker] setCustomVariableAtIndex:1
                                                   name:@"iPhone1"
                                                  value:@"iv1"
                                              withError:&error]

[[GANTracker sharedTracker] trackEvent:@"my_category"
                                   action:@"my_action"
                                    label:@"my_label"
                                    value:-1
                               withError:&error]

[[GANTracker sharedTracker] trackPageview:@"/app_entry_point"
                               withError:&error]

      

Questions

1) What Google Analytics for iOS calls shown above should be in AppDelegate?
2) What Google Analytics for iOS calls shown above can be placed in ViewControllers?

thank

+3


source to share


1 answer


You put the first part in the AppDelegate, that's right.

In the viewDidLoad

method of each element's viewController:

NSError *error;

 if (![[GANTracker sharedTracker] trackPageview:@"/app_entry_point"    
 withError:&error]) {    
 // Handle error here    
 }

      



where @ "/ app_entry_point" should be the name of the ViewController, for example: "/ mainWindow".

The following piece of code used to keep track of your methods being used inside methods.

     NSError *error;
     if (![[GANTracker sharedTracker] trackEvent:@"my_category"        
     action:@"my_action"        
     label:@"my_label"        
     value:-1        
     withError:&error]) {        
     // Handle error here        
     }

      

+3


source







All Articles