Integration & Setup

  1. Home
  2. Integration & Setup
  3. Tracking Code & SDKs
  4. App Analytics tracking framework
  5. iOS implementation

iOS implementation

You add the tracking framework to your application as follows:

1. Copy ‚ETRTracker.h‘ and the associated library ‚libETRTracker.a‘ into your application’s project folder. Make sure that your application links against that static library.

2. In your application delegate, import the header file:

#import "ETRTracker.h"

3. Initialize the tracking service in ‚-application:didFinishLaunchingWithOptions:‘, provide the accountKey and, if necessary, the optional shared secret (API key) you got from etracker resp. registered with your account. By default, pending events are sent to the server once every minute, but you can provide a different time interval. Just overwrite ‚timeInterval:ETRDefaultTimeInterval‘ by your preferred value (in s):

[[ETRTracker sharedTracker] startTrackerWithAccountKey:@"XXXXXX" sharedSecret:@"14a34554" timeInterval:ETRDefaultTimeInterval];

4. Before using the tracking service, you must get user consent to comply with Apple’s terms for application developers. To do this, integrate a code snippet like the following example in your application. By default, user consent is unknown. Due to the code snippet the user will be asked and the tracking service will store the user’s answer. That way, the question is asked only once:

Note: Please notice that no events are tracked until user consent has been given.

- (void)askForUserConsent {
   if ([[ETRTracker sharedTracker] userConsent] == ETRUserConsentUnknown) {
      UIAlertView *alertView = [[UIAlertView alloc]
         message:@"Do you allow anonymous tracking?"
         otherButtonTitles:@"Yes", nil];
        [alertView show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    ETRUserConsent userConsent = buttonIndex ? ETRUserConsentGranted : ETRUserConsentDenied;
    [[ETRTracker sharedTracker] setUserConsent:userConsent];

Handle events

All events are documented in the header file ETRTracker.h that is delivered together with the library. The following events are available:

trackScreenViewScreen call.
trackOrderSending an InApp order.
trackUserDefinedTracks a custom event.

‚trackScreenView‘ and ‚trackOrder‘ are convenience events that simplify the use of custom events. Visitor sessions are determined automatically: Actions in an app within a time interval of 30 minutes are assigned to one visitor session. To track a screen view event, call -trackScreenView: like this:

[[ETRTracker sharedTracker] trackScreenView:@"myScreenView" areas:@"area1/area2/area3"];

To track a user defined event call trackUserDefined like this:

[[ETRTracker sharedTracker] trackUserDefined:@"categoryName" action:@"actionName" object:@"objectName" value:@"42" screenName:@"myScreenView" areas:@"area1/area2/area3"];

If you want to make sure that all pending events are sent to the server immediately, you can call -sendPendingEventsNow. The library will attempt to send all pending events up to twelve times with growing delays.

NEW: Please note, you can also define up to three area levels with both calls and a screenname with the userdefined event

[[ETRTracker sharedTracker] sendPendingEventsNow];

To clean up, we recommend to stop the tracker in -applicationWillTerminate: like this:

[[ETRTracker sharedTracker] stopTracker];