Skip to main content

Android Custom Segments

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


Where possible, it is recommended to set your Custom Segments before starting OpenBack

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

{{ trigger.customSegmentX | default }}

customTriggerX is for backward compatibility - corresponds to customSegmentX

A total of 10 custom segments are available.

public @interface CustomSegmentIndex {}

Creating Custom Segments on the Dashboard

To send a notification to a Custom Segment of users, the Custom Segment must be first created in the dashboard. To add a new Custom Segment to the dashboard, go to your app's settings page and at the bottom of the App Setup tab expand the Advanced Setup section.

Custom Segments

Setting a custom segment value

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

Setting a custom segment will trigger a message check operation.


Setting a Custom Segment will overwrite the previous set value

// 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>();
// Set the array ["Bob", "Jane"] to custom segment 4
OpenBack.setCustomSegment(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

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);

A/B Testing

You can use Custom Segments to create different user groups for A/B testing. When you initialize the SDK, you can randomly assign each user to a different numbered group and then you can specifically target this group when A/B testing. You can use the example code below to quickly assign a user to a random group.

// generate a random number
Random random = new Random();
int group = random.nextInt(5);
OpenBack.setCustomSegment(OpenBack.CUSTOM_SEGMENT_1, group);