Collecting User Data

The strength of Marigold'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

  • Device ID
  • Location based on IP Address
  • Notifications Allowed
  • Platform

๐Ÿ“˜

Note

Attributes tracked automatically are refreshed at every app load.

Registration Events

In order to keep track of a user logging in and out of your app you can log registration events using the logRegistrationEvent method. Supply a string containing the ID you use to track the login, or null/nil for logout.

๐Ÿ“˜

Note

Sailthru customers will use the setUserEmail method instead, see Set User Email

// login
[[Marigold new] logRegistrationEvent:@"user_id_1234"];

// logout
[[Marigold new] logRegistrationEvent:nil];
// login
Marigold().logRegistrationEvent("user_id_1234")

// logout
Marigold().logRegistrationEvent(nil)
// setting a User ID after login
new Marigold().logRegistrationEvent("user_id_1234");


// clearing a User ID after logout
new Marigold().logRegistrationEvent(null);
// login
Marigold().logRegistrationEvent("user_id_1234")

// logout
Marigold().logRegistrationEvent(null)
// login
Marigold.logRegistrationEvent("user_id_1234");

// logout
Marigold.logRegistrationEvent(null);

Tracking Location

By default the Marigold 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:

// must be called before startEngine
[[Marigold new] setGeoIPTrackingDefault:NO];
// must be called before startEngine
Marigold().setGeoIPTrackingDefault(false)
// must be called before startEngine
new Marigold().setGeoIpTrackingDefault(false);
// must be called before startEngine
Marigold().setGeoIpTrackingDefault(false)
// Set as RCTBridgeDelegate
RNSailthruMobileBridge *sailthruMobileBridge = [[RNSailthruMobileBridge alloc]    
                                    initWithJSCodeLocation: jsCodeLocation,
                                                    appKey: SDK_KEY,
                              		 pushAuthorizationOption: STMPushAuthorizationOptionFull,
                                      geoIpTrackingDefault: NO];
// Set as RCTBridgeDelegate
var sailthruMobileBridge = RNSailthruMobileBridge(jsCodeLocation: jsCodeLocation,
                                              			      appKey: SDK_KEY,
                        		 						 pushAuthorizationOption: .full,
                                					  geoIpTrackingDefault: false)
// 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.

[[Marigold new] setGeoIPTrackingEnabled:NO];

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

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

// with result handler
new Marigold().setGeoIpTrackingEnabled(false, new Marigold.MarigoldHandler<Void>() {
    @Override
    public void onSuccess(Void value) {
			// handle success
    }

    @Override
    public void onFailure(Error error) {
			// handle error
    }
});
Marigold().setGeoIpTrackingEnabled(false)

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

  override fun onFailure(error: Error?) {
    // handle error
  }
})
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 Marigold for segmentation.

// On iOS, using Objective-C
[[Marigold new] updateLocation:myLocation]; //Takes an instance of a CLLocation object as a argument.
// On iOS, using Swift
Marigold().updateLocation(myLocation) //Takes an instance of a CLLocation object as a argument.
// On Android, using Java
new Marigold().updateLocation(myLocation); //Takes an instance of a Location object as a argument.
// On Android, using Kotlin
Marigold().updateLocation(myLocation) //Takes an instance of a Location object as a argument.
// 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:

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.

[[Marigold new] deviceID:^(NSString * _Nullable deviceID, NSError * _Nullable error) {
    if(error) {
        // Handle error
        return;
    }
    // Handle deviceID
}];
Marigold().deviceID { (deviceID, errorOrNil) in
	  if let error = errorOrNil {
		    // Handle error
		    return
		}
		// Handle deviceID
}
new Marigold().getDeviceId(new Marigold.MarigoldHandler<String>() {
    @Override
    public void onSuccess(String deviceID) {
        // Handle deviceID
    }

    @Override
    public void onFailure(Error error) {
        // Handle error
    }
});
Marigold().getDeviceId(object : MarigoldHandler<String?> {
  override fun onSuccess(deviceID: String?) {
    // Handle deviceID
  }

  override fun onFailure(error: Error?) {
    // Handle error
  }
})
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 and the Message Stream.

Warning: 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.

[[Marigold new] clearDeviceData:MARDeviceDataTypeEvents | MARDeviceDataTypeMessageStream withResponse:^(NSError * _Nullable error) { 
  // Possible error here
}];
Marigold().clear([.messageStream, .events]) { (error) in
      // Possible error here
  }
//Marigold.MESSAGE_STREAM|Marigold.EVENTS
new Marigold().clearDevice(Marigold.CLEAR_ALL, new Marigold.MarigoldHandler<Void>() {
    @Override
    public void onSuccess(Void value) {

    }

    @Override
    public void onFailure(Error error) {

    }
});
//Marigold.MESSAGE_STREAM|Marigold.EVENTS
Marigold().clearDevice(Marigold.CLEAR_ALL, object : MarigoldHandler<Void?> {
  override fun onSuccess(value: Void?) {

  }

  override fun onFailure(error: Error?) {

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

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