iOS SDK

LivePinch provides a iOS SDK that you can integrate with your android application, and with minimal effort start tracking user. LivePinch iOS SDK provides following features.

  • Track users
  • Track any named application events
  • Track application launches, screen views, sessions, uninstallations and other user activity
  • Send push notifications and track user interactions with push notifications

Tracking Users

By default, Live Pinch tracks all users, and assigns a unique id to every user in order to identify a given user, it is important that you call login method onces a user logs in, and logout method when the user signs out.

Once login is called, All events, page views, clicks, sessions and actions are attributed to the logged in user, until a logout action is called.

Login method accepts a profile_key as an argument. See Profiles section for details on profile_key. Profile Key is a unique identifier for the user on your system, It could be an email, phone or profile_name any other unique identifier you identify the user with.

Profiles section describes the idea of profiles in detail. Profile Key section discusses, in detail, how profile keys are used with in Live Pinch system and how to effectively choose Profile Keys.

Obtaining LivePinch Instance

Start with obtaining an instance of LivePinch.

With Swift

let livePinch:LivePinch = LivePinch.getInstance();

With Objective-C

LivePinch *livePinch = [LivePinch getInstance];

Obtaining LivePinch User Instance

With Swift

// livePinch is intance of LivePinch class, obtained by LivePinch.getInstance();
let livePinchUser :LivePinchUser = livePinch.getUser();

With Objective-C

LivePinchUser *livePinchUser = [ livePinch getUser ];

Login/Logout

As described above, once you identify a given user with Profile Key in order to identify a user, you can either use the LivePinch instance as follows

With Swift

// with LivePinch Instance
livePinch.login( identifier: profile_key )

// Or with LivePinchUser instance
livePinch.login(identifier: profile_key)

With Objective-C

// with LivePinch instance
[ livePinch loginWithIdentifier: profile_key ];

// Or with LivePinchUser instance
[ livePinchUser loginWithIdentifier: profile_key ];

Profile Key document discusses on importance of choosing correct profile keys and ideal candidates for profile keys. The profile_key needs to be of type string. If you’re integer keys, be sure to cast it to string type before calling login.

The usual places to call above method are

  • User signup
  • User login

the identifier provided above remains unchanged until ‘logged out’ method is called.

Logout

Logout must be called when the user logs out of your system or his session times out. When a logout is called. A new anonymous user is created and returning user is tracked under this anonymous Id.

In order to logout, you can either call logout on LivePinch instance or on the LivePinch User Instance object directly

With Swift

// LivePinch instance
livePinch.logout();

// Or LivePinchUser instance
livePinchUser.logout();

Set User Attributes

You can set arbitrary attributes for a given profile. See Profiles section for details on the attributes.

There primarily two ways of setting attributes

  • Set attributes as Dictionary with String keys and one of the allowed values(String,Int,Bool,NSDate)
  • Acquire the attribute builder object build the attributes by chaining serveral calls

Both methods are accessible both on Live Pinch Instance and on Live Pinch User Instance. These are discussed in following passages.

Using Dictionary

With Swift

var dict = Dictionary<String, Any>()

dict = [
  "membership_level":"GOLD",
  "purchase_value":220
  "is_returning_user":true
]

// TODO: Add this

With Objective-C

NSDictionary *dict = [
  [ NSDictionary alloc] initWithObjectsAndKeys:[
    @"GOLD", @"membership_level", 220, @"purchase_value", true, @"is_returning_user", nil
  ]
];

// TODO: Add this

Using Attribute Builder

To obtain an instance of attribute builder

// With LivePinch instance
var attributeBuilder:AttributeBuilder = livePinch.userAttributeBuilder()

// Wtih LivePinchUser instance
var attributeBuilder:AttributeBuilder = livePinchUser.attributeBuilder()
// With LivePinch instance
AttributeBuilder *attributeBuilder = [ livePinch userAttributeBuilder ];

// With LivePinchUser instance
AttributeBuilder *attributeBuilder = [ livePinchUser attributeBuilder ];

with builder instance you can chain several calls, Builder also providers serveral convinience methods to set system attributes. See Profiles section for detailed discussion on system attributes.

Here is a way is an few examples to set attributes with attribute builder

With Swift

// Set predefined system attributes
livePinch.userAttributeBuilder().
  setEmail("john.doe@gmail.com").
  setPhoneNumber("+91991332099").
  build();

// Mix this with setting custom attributes
livePinch.userAttributeBuilder().
  setEmail("john.doe@gmail.com").
  setPhoneNumber("+91991332099").
  set("Membership Level", "GOLD").
  set("Purchase Value", 25.5).
  build();

  // Additionally provide a dictionary to update
  // the attributes with
  livePinch.userAttributeBuilder().
    setEmail("john.doe@gmail.com").
    setPhoneNumber("+91991332099").
    set("Membership Level", "GOLD").
    set("Purchase Value", 25.5).
    updateWithAttributes(dictionary).
    build();


  // Setting Gender, TODO: How do we set this?
  livePinch.userAttributeBuilder().
    setGender(LivePinchUser.Gender.MALE).
    build();

With Objective-C

// Set predefined system attributes
AttributeBuilder *attributeBuilder = [ livePinch userAttributeBuilder ];
[ attributeBuilder setEmail: @"john.doe@gmail.com" ];
[ attributeBuilder setPhoneNumber: @"+91991332099" ];
[ attributeBuilder build ];


// Mix this with setting custom attributes
AttributeBuilder *attributeBuilder = [ livePinch userAttributeBuilder ];
[ attributeBuilder setEmail: @"john.doe@gmail.com" ];
[ attributeBuilder setPhoneNumber: @"+91991332099" ];
[ attributeBuilder setWithAttributeName:@"Membership Level" attributeValue:@"GOLD"];
[ attributeBuilder setWithAttributeName:@"Purchase Value" attributeValue: 25.5];
[ attributeBuilder build ];

// Additionally provide a dictionary to update
// the attributes with
AttributeBuilder *attributeBuilder = [ livePinch userAttributeBuilder ];
[ attributeBuilder setEmail: @"john.doe@gmail.com" ];
[ attributeBuilder setPhoneNumber: @"+91991332099" ];
[ attributeBuilder setWithAttributeName:@"Membership Level" attributeValue:@"GOLD"];
[ attributeBuilder setWithAttributeName:@"Purchase Value" attributeValue: 25.5];
[ attributeBuilder updateWithAttributes: dict ];
[ attributeBuilder build ];

Following are convinience methods to set system attributes. Detailed discussion or attributes and there types can be found at Profiles section.

  • setFirstName
  • setLastName
  • setEmail
  • setGender
  • setBirthDate
  • setCountry
  • setPhoneNumber
  • optforEmail
  • optforSMS

Tracking Events

Events are discussed in detail in the Events section. Please be sure to understand how events are tracked.

Track any custom event the user performs with track event, The first argument is a string, Must be the name of the event, Second attribute is an object containing any arbitrary set of attributes and values that can be associated with this event.

To start tracking, start by obtaining, the tracker object.

Track Event only by event name

All methods are called on LivePinch instance

With Swift

livePinch.getTracker().trackEvent(name: "Product - Screen Viewed");

With Objective-C

[[livePinch getTracker] trackEventWithName:@"Product - Page Viewed"];

Track named event with attributes

With Swift

let addedToCartAttributes: [String:Any]  = [
    "Product ID":1234,
  "Price":100,
  "Product":"Membership",
  "Is Premium":true
]

livePinch.getTracker().trackEvent(name: "Added to Cart", attributes: addedToCartAttributes);

With Objective-C

NSDictionary *addedToCartAttributes=@{
  @"Product ID":@1234,
  @"Price":@100,
  @"Product":@"Membership",
  @"Is Premium":@YES
};

[[livePinch getTracker]trackEventWithName:@"Added to Cart" attributes: addedToCartAttributes ];

Tracking Screen Views

All methods are called on LivePinch instance

To Track Screens,Set following code in viewwillappear,videwilldisappear of whatever screens you need to track.

//Swift

override func viewWillAppear(_ animated: Bool) {
    livePinch.startTrackingScreen(name: "Order Detail")
}

    override func viewWillDisappear(_ animated: Bool) {
    livePinch.stopTrackingScreen(name: "Order Detail")
}

//Objective -C
-(void) viewWillAppear:(BOOL)animated{
    [livePinch startTrackingScreenWithName:@"Order Detail"];
}

-(void) viewWillDisappear:(BOOL)animated{
    [livePinch stopTrackingScreenWithName:@"Order Detail"];
}

Location Tracking

LivePinch sdk provides tracking support for location

Edit your info.plist file by add following key,

  • Privacy - Location When In Use Usage Description
  • Privacy - Location Always Usage Description

Set Values as app provide description to request user to allow location access.

API Key