Latest 0.1.1
Homepage https://github.com/klaviyo/klaviyo-objc-sdk
License MIT
Platforms ios 8.0, requires ARC
Authors

[![CI Status](http://img.shields.io/travis/Katy Keuper/KlaviyoObjC.svg?style=flat)](https://travis-ci.org/Katy Keuper/KlaviyoObjC)
Version
License
Platform

Overview

KlaviyoObjC is an SDK, written im Objective-C, for users to incorporate Klaviyo’s event tracking functionality into iOS applications. We also provide an SDK written in Swift. The two SDKs are identical in their functionality.

Requirements

*iOS >= 8.0

Installation Options

  1. Cocoapods (recommended)
  2. Download the blank, pre-configured project, and get started from scratch.

KlaviyoObjC is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "KlaviyoObjC"

Example Usage: Event Tracking

To run the example project, clone the repo, and run pod install from the Example directory first. Make sure any .m file using the Klaviyo SDK contains the import call.

#import "KlaviyoObjC/Klaviyo.h"

To add Klaviyo’s tracking functionality, it requires just a few lines of code. First, in your application delegate file (under application:didFinishLaunchingWithOptions), add the following line to set up Klaviyo:

[Klaviyo setupWithPublicAPIKey:@"YOUR_PUBLIC_API_KEY"]

The below code example shows how to implement event or person tracking within your application.


    NSMutableDictionary *customerProperties = [NSMutableDictionary new];
    customerProperties[@"$firstName"] = @"John";
    customerProperties[@"$lastName"] = @"Smith";
    [[Klaviyo sharedInstance] trackPersonWithInfo: customerProperties];
    [[Klaviyo sharedInstance] trackEvent:@"Logged In"];

Argument Description

The track function can be called with anywhere between 1-4 arguments:

eventName This is the name of the event you want to track. It can be any string. At a bare minimum this must be provided to track and event.

customer_properties (optional, but recommended) This is a NSMutableDictionary of properties that belong to the person who did the action you’re recording. If you do not include an $email or $id key, the user will be tracked by an $anonymous key.

properties (optional) This is a NSMutableDictionary of properties that are specific to the event. In the above example we included the items purchased and the total price.

eventDate (optional) This is the timestamp (an NSDate) when the event occurred. You only need to include this if you’re tracking past events. If you’re tracking real time activity, you can ignore this argument.

Note that the only argument trackPersonWithInfo takes is a dictionary representing a customer’s attributes. This is different from trackEvent, which can take multiple arguments.

Anonymous Tracking Notice

As of right now, anonymous tracking is not fully functional. What this means is that you cannot call trackEvent with only the eventName parameter unless setUpUserEmail has been called previously. Otherwise you must call trackEvent with an event name and customer properties parameter, including an email address at the very least.

Eventually, once anonymous tracking is enabled you will be able to track events without any user information provided. In the meantime, make sure to pass in an email or id identifier in order for Klaviyo to track events successfully.

Special Properties

As was shown in the examples above, special person and event properties can be used. This works in a similar manner to the Klaviyo Analytics API. These are special properties that can be utilized when identifying a user or an event. They are:

KLPersonEmailDictKey 
KLPersonFirstNameDictKey
KLPersonLastNameDictKey
KLPersonPhoneNumberDictKey
KLPersonTitleDictKey
KLPersonOrganizationDictKey
KLPersonCityDictKey
KLPersonRegionDictKey
KLPersonCountryDictKey
KLPersonZipDictKey
KLEventIDDictKey
KLEventValueDictKey

Lastly, cases where you wish to call trackEvent with only the eventName parameter and not have it result in anonymous user tracking you can use setUpUserEmail to configure your user’s email address. By calling this once, usually upon application login, Klaviyo can track all subsequent events as tied to the given user. However, you are also free to override this functionality by passing in a customer properties dictionary at any time:

[[Klaviyo sharedInstance] setUpUserEmail:@"[email protected]"]; 

Author

Katy Keuper, [email protected]

License

KlaviyoObjC is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "KlaviyoObjC",
    "version": "0.1.1",
    "summary": "Incorporate Klaviyo's event and person tracking functionality into iOS applications'",
    "description": "Use the Klaviyo SDK to incorporate Klaviyo's event and person tracking functionality within iOS applications. Written in Objective-C.'",
    "homepage": "https://github.com/klaviyo/klaviyo-objc-sdk",
    "license": "MIT",
    "authors": {
        "Katy Keuper": "[email protected]"
    },
    "source": {
        "git": "https://github.com/klaviyo/klaviyo-objc-sdk.git",
        "tag": "0.1.1"
    },
    "social_media_url": "https://twitter.com/klaviyoops",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "KlaviyoObjC": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This