iOS
To start working with Journey Analytics JavaScript SDK follow the steps below:
Step 1 – Add Journey Analytics SDK to your project
Make sure that you are using the latest version of Xcode (5.0+), and targeting iOS 7.0 or higher. Demo project for Swift and Objective C can be found in our github repository: https://github.com/cooladata/pod.To add the SDK to your project:
Use CocoaPods:
- Create the Podfile
- If this is your first Pod in your iOS project, create a file named Podfile:
platform :ios, '9.0' use_frameworks! target 'MyApp' do pod 'CoolaPod', '~> 2.5' end
- If you already use CocoaPods in your project, add a reference to Journey Analytics's Pod:
pod 'CoolaPod', '~> 2.5'
- If this is your first Pod in your iOS project, create a file named Podfile:
- Open the terminal app, change dir to your xcode project and run:
$ pod install
This command creates an xcode workspace for your project, and configures it to use CocoaPods.
- From now on, make sure to always open the Xcode workspace instead of the project file when building your project.
Step 2 – Initialization
Add the following import to the top of the AppDelegate.m file.
#import <cooladata-ios-sdk/CoolaDataTracker.h>
Add the following code inside the application:didFinishLaunchingWithOptions function.
[[CoolaDataTracker getInstance] setupWithAppKey:@"aknek0zuo8i4ztcmgopn5wotsceg80m9"];
Step 3 – Track Events
After the Journey Analytics Tracker SDK is properly set up, you are ready to report events from your application. To start doing so, you need to call the trackEvent function with suitable parameters on every users' action that you would like to track.
// set properties on a dictionary
NSDictionary *properies = @{@"Type" : @"Female",
@"Amount" : @2, @"{u}Email":@"sam@email.com"};
// track event with properties
[[CoolaDataTracker getInstance] trackEvent:@"Add Item" properties:properties];
Full API Reference
setupWithApiToken
This method used to initialize a new CoolaData tracker object. Should be called only once from the application:didFinishLaunchingWithOptions.
Name | Type | Mandatory | Description |
---|---|---|---|
appKey | NSString | Yes | The AppKey provided by CoolaData. |
serviceEndPoint | NSString | No | The base URL for the CoolaData Tracker to use when accessing the CoolaData gateway. |
userId | NSString | Yes | The User ID of the current user. Mandatory in the setupWithApiToken function, or in the trackEvent function. I.e. if the User ID provided in the setupWithApiToken, there's no need to send User ID in the trackEvent function, and vice versa. |
sessionId | NSString | No | The Session ID relevant for this instance of the CoolaDataTracker. |
CoolaDataDeliveryResult
This object will be returned from the callback function and contains the following.Parameters
Name | Type | Description |
---|---|---|
eventId | NSString | The ID of the event as specified in the track event. |
status | BOOL | The status of the delivery. False or True. |
deliveryStatusDescription | NSString | The description of the status state. |
deliveryStatusCode | Int | The HTTP error code of the delivery attempt. |
responseProperties | NSDictionary | Custom properties to be sent with the event result. |
trackEvent
Track user' event
Name | Type | Mandatory | Description |
---|---|---|---|
eventName | NSString | Yes | The name of the event to report. This parameter is mandatory. |
withEventId | NSString | No | The Event ID relevant for this event. This parameter is optional. If response block is passed, event id must also be provided. |
userId | NSString | No | The User ID relevant for this event. This parameter is optional only if provided in the setup method. You must provide the userId either in the setup method or in the trackEvent method. |
sessionId | NSString | No | The Session ID relevant for this event. This parameter is optional. |
optionalData | NSString | No | The custom properties to be sent with the event. This parameter is optional. |
error | NSError | No | A pointer to an NSError object. It will be populated with an error in case an immediate error occurs (mandatory parameter was not provided). This parameter is optional. |
responseBlock | Block | No | When calling the track event method, you can pass a response block that will be called with the result/error objects upon receive. For this to happen you must also pass an event id. You can pass the same event id for multiple events. All the blocks related to that event id will be called upon receipt of the related results. This parameter is optional. |