IOS App Tracking

Add iOS libraries

For iPhone, iPad, iPod, AppleTV, etc

Dont have an account? Signup or add your app to an existing account. Opentracker's events engine supports tracking of iOS users and native app events. This is done by including the Opentracker iOS library in your app and following the instructions below. The Opentracker iOS library includes functions and listeners so you can easily insert your custom events into Opentracker.net's events engine.

5 easy steps to start tracking your app

Add iOS libraries

1

Download the iOS client zip file and unzip. You should now have a folder called Opentracker-iOS-xxx
Add Opentracker iOS libraries

2

Open your project in Xcode, and drag the OTLibrary folder (located in the Opentracker-iOS directory) into your application's project directory in order to include the tracking library. Make sure you check the 'Copy items into destination Group's folder' and select 'Create groups for any added folders'. You should now have a new directory in your project called 'OTLibrary' with the Opentracker classes inside.
Add iOS libraries

3

Add the following import statement to your applications delegate file below (eg AppDelegate.m):
#import "OTLogService.h"
		
Opentracker github

4

Next, we have to initialize the OTLogService object in the Application delegate. (AppDelegate.m) This opens the session and logs the session data on start of the application. (example) This is done in the function: applicationDidFinishLaunching or didFinishLaunchingWithOptions of the application.APP_NAME is the name of the application registered in opentracker.
Note: This is an example. your AppDelegate.m will probably look different.
- (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Override point for customization after application launch.
  [[OTLogService sharedOTLogService] onLaunch:@"APP_NAME"];
  [[OTLogService sharedOTLogService] sendEvent:@"start session" ];
}
		
Add the following code to the end of applicationDidEnterBackground. This pauses the session when the app goes into the background and attempts an upload.  (example)
- (void)applicationDidEnterBackground:(UIApplication *)application
{
  [[OTLogService sharedOTLogService] sendEvent:@"application closed" ];
  [[OTLogService sharedOTLogService] onEnteringBackground ];
}
		
Add the following code to the end of applicationWillEnterForeground. This tags an event to resume the previous session or create a new one if more than 30 minutes have passed and upload any data (nothing happens if data was successfully uploaded by the applicationDidEnterBackground call). (example)
- (void)applicationWillEnterForeground:(UIApplication *)application {
  [[OTLogService sharedOTLogService] sendEvent:@"resume session" ];
}
		
Call the following function in the applicationWillTerminate function. Under normal circumstances this function will not be called but there are some cases where the OS will terminate the app.  (example)
- (void)applicationWillTerminate:(UIApplication *)application
{
  //close opentracker session
  [[OTLogService sharedOTLogService] sendEvent:@"application terminated" ];
  [[OTLogService sharedOTLogService] onTerminate];
}
		
Add iOS libraries

5

Finally, we need to add the following 4 Libraries if they are not already included in your project:
  • Libz.dylib
  • SystemConfiguration.framework
  • CoreLocation.framework
  • CoreTelephony.framework

To add these, click on your project in the Project Navigator. You will see the project view. Select your target and click on the 'Build Phases' tab. Open the 'Link Binaries with Libraries' expander and click the '+' button. Search for the above 4 libraries in the list displayed and add them one by one. See screenshot below.

Basic event tracking

Add your events (as many as you like, anywhere you see fit, just like logging).
<span class="pun">[[</span><span class="typ">OTLogService</span><span class="pln"> sharedOTLogService</span><span class="pun">]</span><span class="pln"> sendEvent</span><span class="pun">:@</span><span class="str">"My Event"</span> <span class="pun">];</span>
Note: Dont forget to add the import function from step 4 to all the xxx.Contoller.m files you want to log events in Also: In order to avoid collecting too much data, do not call this function in a loop.

Multi-dimensional events

To use OTLogService to its full potential, you can add property name/ value pairs to an event. For example if you have an event going to an advertisement use the following We recommend adding a title value pair. If there is no title defined, the title will default to '[no title]'. Keys are case-sensitive, hence title value can only be defined for the key 'title' or 'ti'.
// Example of sending a multi-dimensional event
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init ];
  [dictionary setObject:@"HP ad tapped" forKey:@"title"];
  [dictionary setObject:@"http://www.hp.com/external/link.html" forKey:@"ad link"];
  [dictionary setObject:@"$20" forKey:@"value"];
  [dictionary setObject:@"Overview screen" forKey:@"source"];
  [[OTLogService sharedOTLogService]  sendEvent:dictionary ];

Counting

Opentracker's events engine includes counting functionality with segmentation within the API calls.
Info Please see  inserting events with a url for more details on the mechanics

An example

The following example will add a shopping cart event:
// Example of sending a custom event called apple and increase the count by 10
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init ];
  [dictionary setObject:@"My title" forKey:@"title"];
  [dictionary setObject:@"Panasonic Lumix DMC-TZ30" forKey:@"item"];
  [dictionary setObject:@"Panasonic" forKey:@"brand!"];
  [dictionary setObject:@"257" forKey:@"price"];
  [dictionary setObject:@"camera[+257]" forKey:@"itemtype"];
  [[OTLogService sharedOTLogService]  sendEvent:dictionary ];

Click here to see a fully working javascript example

Settings

Enable geo-location

To enable location services, you need to add the parameter [OTLogService setLocationServices: YES] to your AppDelegate file. It is disabled by default.

Overriding default properties

In certain cases you might want to override some values for certain properties. See below for instructions on how to do so.

App & browsers

This property can only be overridden in Android and iOS. You can override the default browser or App name by submitting the 'browser' variable. You can also specify a version. example
  [dictionary setObject:@"My cool app" forKey:@"browser"];
  [dictionary setObject:@"1.5.2" forKey:@"browserVersion"];

Visible in:

  • Apps & Browsers
  • All browser segments

Example

A full example of an iOS xCode project with Opentracker code can be found  here