Collecting User Data

The strength of Mobile's targeting and segmentation relies on knowing the correct information about your users. The more information we know about a user, the better you can target them when you send messages.

When a user installs an app, we collect a few attributes automatically. These attributes are helpful for targeting and segmenting your users.

Automatically Tracked Attributes

    • App Version
    • Language
    • Time Zone
    • Badge Number (iOS only)
    • Device ID
    • Device Make & Model
    • Operating System & Version
  • Mobile SDK version
  • Location based on IP Address
  • Notifications Allowed
  • Platform
Note: Attributes tracked automatically are refreshed at every app load. Beyond the automatically tracked attributes, Mobile also lets you store custom information about a user for further segmenting and targeting. This feature is called User Attributes.

Setting a User ID

If your app has a login, you can set a unique User ID with Mobile. This allows you to associate multiple devices to a single user when targeting via the API. You may also want to collect the user's email as well.

iOS (Objective_C)

// setting a User ID after login
[[SailthruMobile new] setUserId:@"user_id_1234" withResponse:^(NSError *error) {
    NSLog(@"Error setting user id - %@", error.localizedDescription);
}];

// clearing a User ID after logout
[[SailthruMobile new] setUserId:nil withResponse:^(NSError *error) {
    
}];

iOS (Swift)

// setting a User ID after login
SailthruMobile().setUserId("user_id_1234") { error in
    print("setUserID returned with possible error: \(error)")
}

// clearing a User ID after logout
SailthruMobile().setUserId(nil) { error in
    print("setUserID returned with possible error: \(error)")
}

Android (Java)

// setting a User ID after login
new SailthruMobile().setUserId("user_id_1234", new SailthruMobile.SailthruMobileHandler (){

    @Override
    public void onSuccess (Void value){
        //Do Something
    }

    @Override
    public void onFailure (Error error){
        //Do Something
    }
});


// clearing a User ID after logout
new SailthruMobile().setUserId(null, new SailthruMobile.SailthruMobileHandler (){

    @Override
    public void onSuccess (Void value){
        //Do Something
    }

    @Override
    public void onFailure (Error error){
        //Do Something
    }
});

Android (Kotlin)

// setting a User ID after login
SailthruMobile().setUserId("user_id_1234", object : SailthruMobileHandler<Void?> {
  override fun onSuccess(value: Void?) {
    //Do Something
  }

  override fun onFailure(error: Error?) {
    //Do Something
  }
})

// clearing a User ID after logout
SailthruMobile().setUserId(null, object : SailthruMobileHandler<Void?> {
  override fun onSuccess(value: Void?) {
    //Do Something
  }

  override fun onFailure(error: Error?) {
    //Do Something
  }
})

React Native (JavaScript)

// setting a User ID after login
SailthruMobile.setUserId("user_id_1234");

// clearing a User ID after logout
SailthruMobile.setUserId("");
Setting a User ID is optional, but it is strongly recommended. It is a prerequisite to use: Without User ID you will be able to set attributes and events only at the device level.

Setting a User Email

Setting a user email allows to link a device to an identifier user profile, matching the email you provide with an existing Email ID. This is a required step to leverage omnichannel personalization using interests and other data points from the user profile. We recommend to collect both User ID and email.

iOS (Objective-C)

// setting a User ID after login
[[SailthruMobile new] setUserId:@"user_id_1234" withResponse:^(NSError *error) {
NSLog(@"Error setting user id - %@", error.localizedDescription);
}];

// clearing a User ID after logout
[[SailthruMobile new] setUserId:nil withResponse:^(NSError *error) {

}];

iOS (Swift)

// setting a User ID after login
SailthruMobile().setUserId("user_id_1234") { error in
    print("setUserID returned with possible error: \(error)")
}

// clearing a User ID after logout
SailthruMobile().setUserId(nil) { error in
    print("setUserID returned with possible error: \(error)")
}

Android (Java)

// setting a User ID after login
new SailthruMobile().setUserId("user_id_1234", new SailthruMobile.SailthruMobileHandler (){

    @Override
    public void onSuccess (Void value){
        //Do Something
    }

    @Override
    public void onFailure (Error error){
        //Do Something
    }
});


// clearing a User ID after logout
new SailthruMobile().setUserId(null, new SailthruMobile.SailthruMobileHandler (){

    @Override
    public void onSuccess (Void value){
        //Do Something
    }

    @Override
    public void onFailure (Error error){
        //Do Something
    }
});

Android (Kotlin)

// setting a User ID after login
SailthruMobile().setUserId("user_id_1234", object : SailthruMobileHandler<Void?> {
  override fun onSuccess(value: Void?) {
    //Do Something
  }

  override fun onFailure(error: Error?) {
    //Do Something
  }
})

// clearing a User ID after logout
SailthruMobile().setUserId(null, object : SailthruMobileHandler<Void?> {
  override fun onSuccess(value: Void?) {
    //Do Something
  }

  override fun onFailure(error: Error?) {
    //Do Something
  }
})

React Native (JavaScript)

// setting a User ID after login
SailthruMobile.setUserId("user_id_1234");

// clearing a User ID after logout
SailthruMobile.setUserId("");
Setting a User ID is optional, but it is strongly recommended. It is a prerequisite to use:
  • Sending notifications to specific users, including using the Notifications API with user_id audiences
  • Users API
  • Users Events API
  • Audience creation via CSV
Without User ID you will be able to set attributes and events only at the device level.

Setting a User Email

Setting a user email allows to link a device to an identifier user profile, matching the email you provide with an existing Email ID. This is a required step to leverage omnichannel personalization using interests and other data points from the user profile. We recommend to collect both User ID and email.

iOS (Objective-C)

// setting a User Email after login
[[SailthruMobile new] setUserEmail:@"firstname@example.com" withResponse:^(NSError *error) {
NSLog(@"Error setting user email - %@", error.localizedDescription);
}];

// clearing a User Email after logout
[[SailthruMobile new] setUserEmail:nil withResponse:^(NSError *error) {
NSLog(@"Error setting user email - %@", error.localizedDescription);
}];

iOS (Swift)

// setting a User Email after login
SailthruMobile().setUserEmail("firstname@example.com") { error in
print("setUserEmail returned with possible error: \(error)")
}

// clearing a User Email after logout
SailthruMobile().setUserEmail(nil) { error in
print("setUserEmail returned with possible error: \(error)")
}

Android (Java)

// setting a User Email after login
new SailthruMobile().setUserEmail("firstname@example.com", new SailthruMobile.SailthruMobileHandler (){

@Override
public void onSuccess (Void value){
//Do Something
}

@Override
public void onFailure (Error error){
//Do Something
}
});

// clearing a User Email after logout
new SailthruMobile().setUserEmail(null, new SailthruMobile.SailthruMobileHandler (){

@Override
public void onSuccess (Void value){
//Do Something
}

@Override
public void onFailure (Error error){
//Do Something
}
});

Android (Kotlin)

// setting a User Email after login
SailthruMobile().setUserEmail("firstname@example.com", object : SailthruMobileHandler<Void?> {
override fun onSuccess(value: Void?) {
//Do Something
}

override fun onFailure(error: Error?) {
//Do Something
}
})

// clearing a User Email after logout
SailthruMobile().setUserEmail(null, object : SailthruMobileHandler<Void?> {
override fun onSuccess(value: Void?) {
//Do Something
}

override fun onFailure(error: Error?) {
//Do Something
}
})

React Native (JavaScript)

// setting a User Email after login
SailthruMobile.setUserEmail("firstname@example.com");

// clearing a User Email after logout
SailthruMobile.setUserEmail("");

User Attributes

User Attributes provide a powerful and flexible way for developers to store extra metadata for the purposes of grouping, segmenting and targeting users at a later stage. Each User/Device can have multiple attributes. User Attributes are unique to a device and app, and persist between app opens. They are set on the SDK side and saved back to the Mobile platform with the appropriate SDK methods. Each User Attribute has a name, a type and a value. For example;
  • first_name (String)
  • lifetime_value (Float)
  • number_of_items_purchased (Integer)
  • is_premium_subscriber (Boolean)
The following attribute datatypes are supported;
  • Integer (32 bit)
  • Float
  • Date
  • String
  • Boolean
  • Array (of Integer, Floats, Dates and Strings)
To set some User attributes from the SDK

iOS (Objective-C)

// Construct the object
STMAttributes *attributes = [[STMAttributes alloc] init];

// Set one or more attributes
[attributes setString:@"Handbags" forKey:@"last_visited_category"];
[attributes setStrings:@[@"world", @"sports"] forKey:@"subscriptions"];
[attributes setFloat:104.87 forKey:@"customer_ltv"];
[attributes setInteger:3 forKey:@"products_in_cart"];
[attributes setFloats:@[@(36.99), @(42.3)] forKey:@"cart_items_unit_price"];
[attributes setIntegers:@[@(2), @(1)] forKey:@"cart_item_quantities"];
[attributes setBool:YES forKey:@"user_did_use_facebook_login"];
[attributes setDates:@[[NSDate date]] forKey:@"checkout_started"];

// Optional: choose if you want to add new attributes to the existing (update), or if you want to overwrite the current attributes with the new payload (replace). By default, we update.
[attributes setAttributesMergeRule:STMAttributesMergeRuleUpdate];

SailthruMobile *sailthruMobile = [SailthruMobile new];

// Send to Sailthru Mobile
[sailthruMobile setAttributes:attributes withResponse:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error - %@", [error debugDescription]);
}
}];

// Remove an attribute
[sailthruMobile removeAttributeWithKey:@"products_in_cart" withResponse:nil];

iOS (Swift)

// Construct the object
let attributes = STMAttributes()

// Set one or more attributes
attributes.setString("Handbags", forKey: "last_visited_category")
attributes.setStrings(["world", "sports"], forKey: "subscriptions")
attributes.setFloat(104.87, forKey: "customer_ltv")
attributes.setInteger(3, forKey: "products_in_cart")
attributes.setFloats([36.99, 42.3], forKey: "cart_items_unit_price")
attributes.setIntegers([2, 1], forKey: "cart_item_quantities")
attributes.setBool(true, forKey: "user_did_use_facebook_login")
attributes.setDates(NSDate(), forKey: "checkout_started")

// Optional: choose if you want to add new attributes to the existing (update), or if you want to overwrite the current attributes with the new payload (replace). By default, we update.
attributes.setAttributesMergeRule(.Update)

let sailthruMobile = SailthruMobile()

// Send to Sailthru Mobile
sailthruMobile.setAttributes(attributes) { error in
print("setAttributes returned with possible error: \(error)")
}

// Remove an attribute
sailthruMobile.removeAttributeWithKey("products_in_cart", nil)

Android (Java)

// Construct the object AttributeMap attributes = new AttributeMap(); // Set one or more attributes attributes.putString("last_visited_category", "Handbags"); ArrayList subscriptions = new ArrayList<>(Arrays.asList("world", "sports")); attributes.putStringArray("subscriptions", subscriptions); attributes.putFloat("customer_ltv", 104.87f); ArrayList cartItemsUnitPrice = new ArrayList<>(Arrays.asList(36.99f, 42.3f)); attributes.putFloatArray("cart_items_unit_price", cartItemsUnitPrice); attributes.putInt("products_in_cart", 3); ArrayList cartItemQuantities = new ArrayList<>(Arrays.asList(2, 1)); attributes.putIntArray("cart_item_quantities", cartItemQuantities); attributes.putBoolean("user_did_user_facebook_login", true); attributes.putDate("checkout_started", new Date()); // Optional: choose if you want to add new attributes to the existing (update), or if you want to overwrite the current attributes with the new payload (replace). By default, we update. attributes.setMergeRules(AttributeMap.RULE_UPDATE); SailthruMobile sailthruMobile = new SailthruMobile(); // Send to Sailthru Mobile sailthruMobile.setAttributes(attributes, new SailthruMobile.AttributesHandler() { @Override public void onSuccess() { // Handle success here } @Override public void onFailure(Error error) { // Handle failure here Log.d("YOUR_LOG_TAG", "setAttributes returned with possible error: " + error.getLocalizedMessage()); } }); // Remove an attribute sailthruMobile.removeAttribute("products_in_cart");

Android (Kotlin)

// Construct the object
val attributes = AttributeMap()

// Set one or more attributes
attributes.putString("last_visited_category", "Handbags")

val subscriptions: ArrayList<String> = ArrayList(Arrays.asList("world", "sports"))
attributes.putStringArray("subscriptions", subscriptions)

attributes.putFloat("customer_ltv", 104.87f)

val cartItemsUnitPrice: ArrayList<Float> = ArrayList(Arrays.asList(36.99f, 42.3f))
attributes.putFloatArray("cart_items_unit_price", cartItemsUnitPrice)

attributes.putInt("products_in_cart", 3)

val cartItemQuantities: ArrayList<Int> = ArrayList(Arrays.asList(2, 1))
attributes.putIntArray("cart_item_quantities", cartItemQuantities)

attributes.putBoolean("user_did_user_facebook_login", true)
attributes.putDate("checkout_started", Date())

// Optional: choose if you want to add new attributes to the existing (update), or if you want to overwrite the current attributes with the new payload (replace). By default, we update.
attributes.setMergeRules(AttributeMap.RULE_UPDATE)

val sailthruMobile = SailthruMobile()

// Send to Sailthru Mobile
sailthruMobile.setAttributes(attributes, object : SailthruMobile.AttributesHandler {
  override fun onSuccess() {
    // Handle success here
  }

  override fun onFailure(error: Error?) {
    // Handle failure here
    Log.d("YOUR_LOG_TAG", "setAttributes returned with possible error: " + error!!.localizedMessage)
  }
})

// Remove an attribute
sailthruMobile.removeAttribute("products_in_cart")

React Native (JavaScript)

// Construct the object
var attrMap = new SailthruMobile.AttributeMap();

// Set one or more attributes
attrMap.setString("string_key", "This is the string value");
attrMap.setStringArray("strings_key", ["This is first value", "This is the second value"]);
attrMap.setDate("date_key", new Date());
attrMap.setDateArray("dates_key", [new Date(), new Date(), new Date()]);
attrMap.setFloat("float_key", 3.141);
attrMap.setFloatArray("floats_key", [1.1, 2.2, 3.3, 4.4]);
attrMap.setInteger("integer_key", 3);
attrMap.setIntegerArray("integers_key", [1, 2, 3, 4]);
attrMap.setBoolean("boolean_key", true);

// Optional: choose if you want to add new attributes to the existing (update), or if you want to overwrite the current attributes with the new payload (replace). By default, we update.
attrMap.setMergeRule(attrMap.MergeRules.Update);

// Send to Sailthru Mobile
SailthruMobile.setAttributes(attrMap).catch(e => {
  // Handle error
});

Custom Attribute Limits

There are limits in place on the maximum number of custom attributes allowed as well as the length (size) of strings and arrays.
  • A maximum of 50 custom attributes is allowed per device. If you exceed this amount any new attributes being set will be discarded.
  • String values that have more than 255 characters will be truncated.
  • Arrays with more than 50 elements will be truncated.

Key name restrictions

  • Only letters, numbers, underscore and dashes are valid characters.
  • Leading spaces will be removed.
  • Invalid characters other than spaces and dots will be removed.
  • Spaces and dots will be replaced for underscores.
  • Keys will be truncated to a maximum of 255 characters.
  • Invalid keys will simply be discarded and no error will be returned.
Note: Custom attributes are refreshed in real time.

Profile Vars

Profile Vars can be set and retrieved through the SDK. This makes maintaining state between your email/on-site campaigns and your mobile marketing easy. Note that the use of this feature requires that your app be linked to Email/On-Site. Vars should be set in a JSON object format:

iOS (Objective-C)

// Setup profile vars object
NSDictionary *profileVars = @{
    @"string_key" : @"string_value",
    @"object_key" : @{},
    @"boolean_key" : @YES
};
    
// Set profile vars
[[SailthruMobile new] setProfileVars:profileVars withResponse:^(NSError * _Nullable error) {
    // Check if error is non-nil for result
}];

iOS (Swift)

// Setup profile vars object
let profileVars : [String : Any] = [ 
    "string_key" : "string_value",
    "object_key" : [],
    "boolean_key" : true 
]

// Set profile vars
SailthruMobile().setProfileVars(profileVars) { (error : Error?) in
    // Check if error is non-nil for result
}

Android (Java)

// Setup profile vars object
JSONObject profileVars = new JSONObject();
profileVars.put("string_key", "string_value");
profileVars.put("object_key", new JSONObject());
profileVars.put("boolean_key", true);

// Set profile vars
new SailthruMobile().setProfileVars(profileVars, new SailthruMobile.SailthruMobileHandler<Void>() {
    @Override
    public void onSuccess(Void value) {
        // Handle success
    }

    @Override
    public void onFailure(Error error) {
        // Handle error
    }
});

Android (Kotlin)

// Setup profile vars object
val profileVars = JSONObject()
profileVars.put("string_key", "string_value")
profileVars.put("object_key", JSONObject())
profileVars.put("boolean_key", true)

// Set profile vars
SailthruMobile().setProfileVars(profileVars, object : SailthruMobileHandler<Void?> {
  override fun onSuccess(value: Void?) {
    // Handle success
  }

  override fun onFailure(error: Error?) {
    // Handle error
  }
})

React Native (JavaScript)

// Setup profile vars object
var profileVars = {
  "string_key" : "string_value",
  "object_key" : {},
  "boolean_key": true
};

// Set profile vars
SailthruMobile.setProfileVars(profileVars).then(result => {
  // Handle success
}).catch(e => {
  // Handle error
});
When retrieving vars they will be returned in the same JSON object format:

iOS (Objective-C)

[[SailthruMobile new] getProfileVarsWithResponse:^(NSDictionary<NSString *,id> * _Nullable profileVars, NSError * _Nullable error) {
    // Handle profileVars object or error
}];

iOS (Swift)

SailthruMobile().getProfileVars { (profileVars : [String : Any]?, error : Error?) in
    // Handle profileVars object or error
}

Android (Java)

new SailthruMobile.getProfileVars(new SailthruMobile.SailthruMobileHandler<JSONObject>() {
    @Override
    public void onSuccess(JSONObject profileVars) {
        // Handle profileVars object
    }

    @Override
    public void onFailure(Error error) {
        // Handle error
    }
});

Android (Kotlin)

SailthruMobile().getProfileVars(object : SailthruMobileHandler<JSONObject?> {
  override fun onSuccess(profileVars: JSONObject?) {
    // Handle profileVars object
  }

  override fun onFailure(error: Error?) {
    // Handle error
  }
})

React Native (JavaScript)

SailthruMobile.getProfileVars().then(profileVars => {
  // Handle profileVars object
}).catch(e => {
  // Handle error
});

Variable Names

  • Are case sensitive. For example, if you create a variable named "Survey_Score" it will not be accessible using all lowercase letters.
  • May not start with a number or be only numbers. For example, don't upload phone numbers using var name "#".
  • May not contain special characters (such as %, -, or $). These characters will be scrubbed from variable names upon import.
  • May not contain spaces. If the variable name is submitted with a space, it will be converted to an underscore.

Date and Time Formats

  • In order to maintain strict JSON compatibility, vars do not support a native date or time type. Instead, if you use specific naming and formatting conventions, these values are treated as dates and times throughout our system, for example, when performing queries in Audience Builder.
For more information on Vars, see the User Variables docs

Custom Events

Mobile's Custom Events provide a simple event tracking solution for measuring actions in your app. Events can be logged to track actions that users take, such as screen views, or social network shares. Unlike user attributes, events occur over time and graphs of the events can be seen within the analytics section of the Mobile dashboard. Mobile keeps record of the count and the last occurrence of an event for each user, so you can target and segment based on;
  • Whether a user has performed this event or not
  • When they last performed this event
  • How often they have performed this event
These events are also passed through to the Lifecycle Optimiser where they can be used to build powerful workflows for both mobile and email.

Log a Custom Event

iOS (Objective-C)

SailthruMobile *sailthruMobile = [SailthruMobile new];
[sailthruMobile logEvent:@"Checkout started"];
[sailthruMobile logEvent:@"Article shared"];

// with Vars
NSDictionary* eventVars = @{ @"itemCount" : @3 };
[sailthruMobile logEvent:@"Checkout started" withVars:eventVars];

iOS (Swift)

let sailthruMobile = SailthruMobile()
sailthruMobile.logEvent("Checkout started")
sailthruMobile.logEvent("Article shared")

// with Vars
let eventVars = [ "itemCount" : 3 ]
sailthruMobile.logEvent("Checkout started", withVars: eventVars)

Android (Java)

SailthruMobile sailthruMobile = new SailthruMobile();
sailthruMobile.logEvent("Checkout started");
sailthruMobile.logEvent("Article shared");

// with Vars
JSONObject eventVars = new JSONObject().put("itemCount", 3);
sailthruMobile.logEvent("Checkout started", eventVars);

Android (Kotlin)

val sailthruMobile = SailthruMobile()
sailthruMobile.logEvent("Checkout started")
sailthruMobile.logEvent("Article shared")

// with Vars
val eventVars = JSONObject().put("itemCount", 3)
sailthruMobile.logEvent("Checkout started", eventVars)

React Native (JavaScript)

SailthruMobile.logEvent("Checkout started");
SailthruMobile.logEvent("Article shared");

// with Vars
var eventVars = {
  "itemCount" : 3
};
SailthruMobile.logEvent("Checkout started", eventVars);
Note: The maximum amount of unique events which can be registered per device is limited to 50. Events are updated in batch, close to real-time, every few seconds.

Auto-Analytics Tracking

On iOS

The Mobile iOS SDK automatically integrates with other analytics providers to capture some analytics. At the moment we capture only event data. This means that if you use the frameworks below to log events, they'll also be logged to Mobile as an event also. The providers we integrate with are:
  • Google Analytics
  • Mixpanel
  • Adobe Analytics (Formerly Omniture)
  • Localytics
  • Amplitutde
  • Flurry
Auto-Analytics is opt-in. To enable Auto-Analytics, use the enableAutoAnalytics method.

iOS (Objective-C)

//Call as early as possible, perhaps straight after startEngine

[[SailthruMobile new] enableAutoAnalytics:@[STMAutoAnalyticsSourceGoogleAnalytics, STMAutoAnalyticsSourceAdobe, STMAutoAnalyticsSourceMixpanel, STMAutoAnalyticsSourceLocalytics]];

iOS (Swift)

//Call as early as possible, perhaps straight after startEngine

SailthruMobile().enableAutoAnalytics([STMAutoAnalyticsSourceGoogleAnalytics, STMAutoAnalyticsSourceAdobe, STMAutoAnalyticsSourceMixpanel, STMAutoAnalyticsSourceLocalytics])

Methods captured

Google Analytics
  • + (id)createEventWithCategory:(NSString *)category action:(NSString *)action label:(NSString *)label value:(NSString *)value We discard categorylabel and value, and log a Mobile event with the action as the name.
Adobe Analytics
  • + (void)trackAction:(NSString *)action data:(id)data We discard data and log a Mobile event with the action as the name.
Mixpanel
  • - (void)track:(NSString *)event properties:(NSString *)properties We discard properties and log a Mobile event with the event as the name.
Localytics
  • - (void)tagEvent:(NSString *)eventName attributes:(NSDictionary *)attributes customerValueIncrease:(NSNumber *)customerValueIncrease;
We discard attributes and customerValueIncrease, and log a Mobile event with the eventName as the name.
Flurry
  • + (NSInteger)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters timed:(BOOL)timed
  • + (NSInteger)logEvent:(NSString *)eventName timed:(BOOL)timed
We discard eventNameparameters and timed, and log a Mobile event with the eventName as the name.
Amplitude
  • - (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)eventProperties withApiProperties:(NSDictionary *)apiProperties withUserProperties:(NSDictionary *)userProperties withGroups:(NSDictionary *)groups withTimestamp:(NSNumber *)timestamp outOfSession:(BOOL)outOfSession (Other event methods call this method)
We discard most parameters, and log a Mobile event with the eventType as the name.

On Android

For Auto-Analytics Tracking on Android, the logEvent() call now takes a source parameter for when forwarding events from other analytics frameworks to Mobile. This allows you to target based on events you already track.
new SailthruMobile().logEvent("source", "myEvent");
A selection of pre-written integrations have been provided, allowing you to just include one file, replace your event logging calls and then turn on or off the frameworks you want to use by commenting them out in the source file provided. User Attributes or Custom Events? User Attributes don't record events that happen over time, and don't appear in graphs in the platform. They are simply metadata for a user. For recording events that happen over time, so you can target users by behavior, you should use our custom events feature.

Tracking Location

By default the Mobile platform collects a last known IP location for each user. This can be used for coarse location segmentation and targeting with no extra development effort or permissions in your app. Depending on local laws, you may need to obtain the express consent from your app users in order to track IP location. You can disabled IP location by default if required:

iOS (Objective-C)

// must be called before startEngine
[[SailthruMobile new] setGeoIPTrackingDefault:NO];

iOS (Swift)

// must be called before startEngine
SailthruMobile().setGeoIPTrackingDefault(false)

Android (Java)

// must be called before startEngine
new SailthruMobile().setGeoIpTrackingDefault(false);

Android (Kotlin)

// must be called before startEngine
SailthruMobile().setGeoIpTrackingDefault(false)

React Native - iOS (Objective-C)

// Set as RCTBridgeDelegate
RNSailthruMobileBridge *sailthruMobileBridge = [[RNSailthruMobileBridge alloc]    
                                    initWithJSCodeLocation: jsCodeLocation,
                                                    appKey: SDK_KEY,
                                   pushAuthorizationOption: STMPushAuthorizationOptionFull,
                                      geoIpTrackingDefault: NO];

React Native - iOS (Swift)

// Set as RCTBridgeDelegate
var sailthruMobileBridge = RNSailthruMobileBridge(jsCodeLocation: jsCodeLocation,
                                                          appKey: SDK_KEY,
                                         pushAuthorizationOption: .full,
                                            geoIpTrackingDefault: false)

React Native (JavaScript)

// Added to list of ReactPackages
RNSailthruMobilePackage.Builder.createInstance(getApplicationContext(),
                            "ec27b1ca830238179747e2b812ad38bfcd4f9823")
                            .setGeoIPTrackingDefault(false)
                            .build()
You can also enable or disable it later for an existing device.

iOS (Objective-C)

[[SailthruMobile new] setGeoIPTrackingEnabled:NO];

// with result handler
[[SailthruMobile new] setGeoIPTrackingEnabled:NO withResponse:^(NSError * _Nullable error) {
    // Check if error is non-nil for result
}];

iOS (Swift)

SailthruMobile().setGeoIPTrackingEnabled(false)

// with result handler
SailthruMobile().setGeoIPTrackingEnabled(false) { (error : Error?) in
    // Check if error is non-nil for result
}

Android (Java)

new SailthruMobile().setGeoIpTrackingEnabled(false);

// with result handler
new SailthruMobile().setGeoIpTrackingEnabled(false, new SailthruMobile.SailthruMobileHandler() {
    @Override
    public void onSuccess(Void value) {
      // handle success
    }

    @Override
    public void onFailure(Error error) {
      // handle error
    }
});

Android (Kotlin)

SailthruMobile().setGeoIpTrackingEnabled(false)

// with result handler
SailthruMobile().setGeoIpTrackingEnabled(false, object : SailthruMobileHandler<Void?> {
  override fun onSuccess(value: Void?) {
    // handle success
  }

  override fun onFailure(error: Error?) {
    // handle error
  }
})

"React

SailthruMobile.setGeoIPTrackingEnabled(false); // with result handler SailthruMobile.setGeoIPTrackingEnabled(false).then(result => { // Handle success }).catch(e => { // Handle error });
In order to support more granular location, it is up to the app to decide and manage the accuracy of capturing location information, while considering the user's battery life. It's best practice to use only the accuracy you need for messaging (Block, City, State, Country). Location updates can then be passed through to Mobile for segmentation.

iOS (Objective-C)

// On iOS, using Objective-C
[[SailthruMobile new] updateLocation:myLocation]; //Takes an instance of a CLLocation object as an argument.

iOS (Swift)

// On iOS, using Swift
SailthruMobile().updateLocation(myLocation) //Takes an instance of a CLLocation object as an argument.

Android (Java)

// On Android, using Java
new SailthruMobile().updateLocation(myLocation); //Takes an instance of a Location object as an argument.

Android (Kotlin)

// On Android, using Kotlin
SailthruMobile().updateLocation(myLocation) //Takes an instance of a Location object as an argument.

React Native (JavaScript)

// On React Native, using JavaScript
SailthruMobile.updateLocation(lat, lon); //Takes lattitude and longitude as arguments
Below are some short tutorials for collecting a user's location on Both iOS and Android:
  • Location Tracking on iOS
  • Location Tracking on Android

Getting the Device ID

You can retrieve the device ID from the SDK if you would like to use it in your app. The device ID will be returned as a string in an asynchronous operation.

iOS (Objective-C)

[[SailthruMobile new] deviceID:^(NSString * _Nullable deviceID, NSError * _Nullable error) {
    if(error) {
        // Handle error
        return;
    }
    // Handle deviceID
}];

iOS (Swift)

SailthruMobile().deviceID { (deviceID, errorOrNil) in
    if let error = errorOrNil {
        // Handle error
        return
    }
    // Handle deviceID
}

Android (Java)

new SailthruMobile().getDeviceId(new SailthruMobile.SailthruMobileHandler() {
    @Override
    public void onSuccess(String deviceID) {
        // Handle deviceID
    }

    @Override
    public void onFailure(Error error) {
        // Handle error
    }
});

Android (Kotlin)

SailthruMobile().getDeviceId(object : SailthruMobileHandler<String?> {
  override fun onSuccess(deviceID: String?) {
    // Handle deviceID
  }

  override fun onFailure(error: Error?) {
    // Handle error
  }
})

React Native (JavaScript)

SailthruMobile.getDeviceID().then(function(deviceID) {
    // Handle device ID
}, function(error){
    // Handle error
});

Clearing Device Data

At times, such as a logging out flow or a user settings screen, you might want to clear device data. You're able to clear data for Events, Custom Attributes and Message Stream. Note: By clearing events or custom attributes, the device may become eligible for an automated message triggered based on leaving an audience. Double check your set up before using this method.

iOS (Objective-C)

[[SailthruMobile new] clearDeviceData:STMDeviceDataTypeEvents | STMDeviceDataTypeAttributes | STMDeviceDataTypeMessageStream withResponse:^(NSError * _Nullable error) { 
  // Possible error here
}];

iOS (Swift)

SailthruMobile().clear([.attributes, .messageStream, .events]) { (error) in
      // Possible error here
  }

Android (Java)

//SailthruMobile.ATTRIBUTES|SailthruMobile.MESSAGE_STREAM|SailthruMobile.EVENTS
new SailthruMobile().clearDevice(SailthruMobile.CLEAR_ALL, new SailthruMobile.SailthruMobileHandler() {
    @Override
    public void onSuccess(Void value) {

    }

    @Override
    public void onFailure(Error error) {

    }
});

Android (Kotlin)

//SailthruMobile.ATTRIBUTES|SailthruMobile.MESSAGE_STREAM|SailthruMobile.EVENTS
SailthruMobile().clearDevice(SailthruMobile.CLEAR_ALL, object : SailthruMobileHandler<Void?> {
  override fun onSuccess(value: Void?) {

  }

  override fun onFailure(error: Error?) {

  }
})

React Native (JavaScript)

// Clear one or more types. Specify one or more of these values.
SailthruMobile.clearDevice(
  SailthruMobile.DeviceValues.Attributes | 
  SailthruMobile.DeviceValues.MessageStream |
  SailthruMobile.DeviceValues.Events);

// Clear all device data
SailthruMobile.clearDevice(SailthruMobile.DeviceValues.ClearAll);

Contact us

Top