Skip to content

Custom Segments

Custom segments are set by your mobile app and used to trigger a message when the value set by the mobile app matches the value set in the message through the OpenBack Dashboard or Client API. The values set can also be used as personalised content within messages.

The replacement is done using a subset of the mustache format:

{{ trigger.customTriggerX | default }}

A total of 10 custom segments are available.

@IntDef({
    CUSTOM_SEGMENT_1, CUSTOM_SEGMENT_2, 
    CUSTOM_SEGMENT_3, CUSTOM_SEGMENT_4, 
    CUSTOM_SEGMENT_5, CUSTOM_SEGMENT_6, 
    CUSTOM_SEGMENT_7, CUSTOM_SEGMENT_8, 
    CUSTOM_SEGMENT_9, CUSTOM_SEGMENT_10
})
public @interface CustomSegmentIndex {}

Setting a custom segment value

Custom segment value can be a string, a long, a double or a list of strings. The latter is used for the IN and CONTAINS operator.

Setting a custom segment will trigger a message check operation.

// Set the string Test to custom segment 1
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_1, "Test");
// Set the long value 42 to custom segment 2
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_2, 42);
// Set the double value 23.4 to custom segment 3
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_3, 23.4);

ArrayList<String> names = new ArrayList<String>(); 
names.add("Bob");
names.add("Jane");
// Set the array ["Bob", "Jane"] to custom segment 4
OpenBack.setCustomSegment(CUSTOM_SEGMENT_4, names);
// Set the string Test to custom segment 1
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_1, "Test")
// Set the long value 42 to custom segment 2
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_2, 42)
// Set the double value 23.4 to custom segment 3
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_3, 23.4)

val names: ArrayList<String> = ArrayList()
names.add("Bob")
names.add("Jane")
// Set the array ["Bob", "Jane"] to custom segment 4
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_4, names)

Clearing a custom segment value

// Clear the value of custom segment 1
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_1, null);
// Clear all the custom segments
OpenBack.removeAllCustomSegments();
// Clear the value of custom segment 1
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_1, null)
// Clear all the custom segments
OpenBack.removeAllCustomSegments()

Getting a custom segment value

// Get the Object value of custom segment 1
// If value is null, custom segment 1 is not set
Object value = OpenBack.getCustomSegment(OpenBack.CUSTOM_SEGMENT_1);

// Get the string value of custom segment 1
String value = OpenBack.getCustomSegmentAsString(OpenBack.CUSTOM_SEGMENT_1);
// Get the long value of custom segment 1 - defaults to 0
long value = OpenBack.getCustomSegmentAsLong(OpenBack.CUSTOM_SEGMENT_1);
// Get the double value of custom segment 1 - defaults to 0.0
double value = OpenBack.getCustomSegmentAsDouble(OpenBack.CUSTOM_SEGMENT_1);
// Get the Object value of custom segment 1
// If value is null, custom segment 1 is not set
val value = OpenBack.getCustomSegment(OpenBack.CUSTOM_SEGMENT_1)

// Get the string value of custom segment 1
val value: String? = OpenBack.getCustomSegmentAsString(OpenBack.CUSTOM_SEGMENT_1)
// Get the long value of custom segment 1 - defaults to 0
val value = OpenBack.getCustomSegmentAsLong(OpenBack.CUSTOM_SEGMENT_1)
// Get the double value of custom segment 1 - defaults to 0.0
val value = OpenBack.getCustomSegmentAsDouble(OpenBack.CUSTOM_SEGMENT_1)