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.
1 | Signup or add your app to an existing account (receive signup email). | |
2 | Download the iOS client zip file and unzip. You should now have a folder called Opentracker-iOS-xxx | |
3 | 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. 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. |
|
4 |
Add the following import statement to your application's delegate file below (eg
<YourApplication>AppDelegate.m):
#import "OTLogService.h" |
|
5 |
Next, we have to initialize the OTLogService object in the Application delegate.
(<YourApplication>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 - (void)applicationDidEnterBackground:(UIApplication *)application { [[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] onTerminate]; } |
|
6 |
Add your events (as many as you like, anywhere you see fit, just like logging).
[[OTLogService sharedOTLogService] sendEvent:@"My Event" ];
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. |
|
7 |
Finally, we need to add the following 4 Libraries if they are not already included in your project:
|
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]'
// 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 ];
Opentracker's events engine includes counting functionality with segmentation within the API calls.
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:@"title" forKey:@"My 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 ];
To enable location services, you need to add the parameter [OTLogService setLocationServices:YES]
to your AppDelegate
file. It is disabled by default.
A full example of an iOS xCode project with Opentracker code can be found here
In certain cases you might want to override some values for certain properties. See below for instructions on how to do so.
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: