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:

  1. 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'
  2. 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.

  3. 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"];
Note: The CoolaDataTracker is a singleton. Its reference can be obtained by calling the getInstance method: [CoolaDataTracker getInstance]. Creating the new instance of the CoolaDataTracker object manually will cause an error; therefore do not call [CoolaDataTracker alloc] init].

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.

NameTypeMandatoryDescription
appKeyNSStringYesThe AppKey provided by CoolaData.
serviceEndPointNSStringNoThe base URL for the CoolaData Tracker to use when accessing the CoolaData gateway.
userIdNSStringYesThe 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.
sessionIdNSStringNoThe Session ID relevant for this instance of the CoolaDataTracker.

CoolaDataDeliveryResult

This object will be returned from the callback function and contains the following.Parameters

NameTypeDescription
eventIdNSStringThe ID of the event as specified in the track event.
statusBOOLThe status of the delivery. False or True.
deliveryStatusDescriptionNSStringThe description of the status state.
deliveryStatusCodeIntThe HTTP error code of the delivery attempt.
responsePropertiesNSDictionaryCustom properties to be sent with the event result.

trackEvent

Track user' event

NameTypeMandatoryDescription
eventNameNSStringYesThe name of the event to report. This parameter is mandatory.
withEventIdNSStringNoThe Event ID relevant for this event. This parameter is optional. If response block is passed, event id must also be provided.
userIdNSStringNoThe 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.
sessionIdNSStringNoThe Session ID relevant for this event. This parameter is optional.
optionalDataNSStringNoThe custom properties to be sent with the event. This parameter is optional.
errorNSErrorNoA 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.
responseBlockBlockNoWhen 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.