iOS 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 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.customTriggerX | default }}

A total of 10 custom segments are available.

enum OBKCustomSegmentType : Int {
case kOBKCustomSegment1 = 0
case kOBKCustomSegment2 = 1
case kOBKCustomSegment3 = 2
case kOBKCustomSegment4 = 3
case kOBKCustomSegment5 = 4
case kOBKCustomSegment6 = 5
case kOBKCustomSegment7 = 6
case kOBKCustomSegment8 = 7
case kOBKCustomSegment9 = 8
case kOBKCustomSegment10 = 9

Full API documentation here

Setting a custom segment value

Custom segment value can be a NSString or NSInteger.

Setting a custom segment will trigger a message check operation.

OpenBack.setValue("123", for: .segment1)
OpenBack.setValue(123, for: .segment2)

Clearing a custom segment value

// Clear the value of custom segment 1
OpenBack.setValue(nil, for: .segment1)
// Clear all the custom segments

Getting a custom segment value

// Get the Object value of custom segment 1
// If value is nil, custom segment 1 is not set
var value = OpenBack.getCustomSegment(.segment1)

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
let group = Int.random(in: 1...5);
OpenBack.setValue(group, for: .segment1)