Skip to content

data-cortex/cortex-ios-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cortex-ios-sdk

Data Cortex iOS SDK

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

cortex-ios-sdk is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DataCortex"

Make sure you include the following in your Info.plist

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
   <key>api.data-cortex.com</key>
   <dict>
    <key>NSTemporaryThirdPartyExceptionRequiresForwardSecrecy</key>
    <false/>
   </dict>
  </dict>
</dict>

Initializing the library

Generally you initialize the library in your AppDelegate.m file. application:willFinishLaunchingWithOptions:

#import <DataCortex/DataCortex.h>

#define DC_API_KEY @"YOUR_API_KEY"
#define DC_ORG @"your_org_name"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  // Initialize the library with your DC_API_KEY
  [DataCortex sharedInstanceWithAPIKey:YOUR_API_KEY forOrg:DC_ORG];

  // To get your instance later
  DataCortex *dc = [DataCortex sharedInstance];

//...

}

You can also specify your DAU tracking time zone, otherwise we assume UTC.

  // Initialize the library with your DC_API_KEY
  [DataCortex sharedInstanceWithAPIKey:YOUR_API_KEY
                                forOrg:DC_ORG
                           dauTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"PST"]];

User tracking

If you have a user ID or other identifier you track users by, add this to Data Cortex to aggregate the user's usage across multiple devices and platforms.

  DataCortex *dc = [DataCortex sharedInstance];

  // User identified by Numeric ID
  [dc setUserTag:@1234];
  // User identified by unique string
  [dc setUserTag:@"xzy123"];

Event Tracking

Event tracking is the bulk of the ways you'll use the Data Cortex SDK. Please refer to your tracking specification for the parameters to use in each event.

  DataCortex *dc = [DataCortex sharedInstance];

  // With all taxonomy
  [dc eventWithProperties:@{
    @"kingdom": @"kingdom",
    @"phylum": @"phylum",
    @"class": @"class",
    @"order": @"order",
    @"family": @"family",
    @"genus": @"genus",
    @"species": @"species",
  }];

  // With all taxonomy and floats
  [dc eventWithProperties:@{
    @"kingdom": @"kingdom",
    @"phylum": @"phylum",
    @"class": @"class",
    @"order": @"order",
    @"family": @"family",
    @"genus": @"genus",
    @"species": @"species",
    @"float1": @123,
    @"float2": @1.5,
    @"float3": @100000,
    @"float4": @0.0,
  }];

Economy tracking

Economy tracking is very similar to event tracking but adds a few extra required elements. Specifically spendAmount and spendCurrency. It also adds an optional spendType.

  DataCortex *dc = [DataCortex sharedInstance];

  [dc economyWithProperties:@{
      @"kingdom": @"kingdom",
      @"phylum": @"phylum",
      @"class": @"class",
      @"order": @"order",
      @"family": @"family",
      @"genus": @"genus",
      @"species": @"species",
    }
    spendAmount: @9.99
    spendCurrency: @"USD"
    spendType: @"coinPurchase"
  }];

  [dc economyWithProperties:@{
      @"kingdom": @"buildings",
      @"phylum": @"barn",
      @"class": @"red",
    }
    spendAmount: @10
    spendCurrency: @"coins"
  }];