Skip to main content
Version: 1.4.x

Extension Point: Customer Events

Basics​

ParameterValue
Extension Point KeyCUSTOMER_EVENT
Extension Point NameCustomer Event
Extension InterfaceCustomerEvent
Supports Multiple Extensions?Yes
Selector TypeNone
Available Since1.3.0

Use Cases​

Extensions implementing this Extension Point are notified when customer events occur.

Methods​

getDeliveryPolicy​

The getDeliveryPolicy method is invoked during Integration Server startup. It allows the extension to define how retries should be handled if the extension throws an exception. The extension needs to return the following values in the XPFDeliveryPolicy response object:

  • consumerQueueName: An identifier for the consumer message queue that will be used to track events and allow them to be processed asynchronously. This value should be unique for all extensions assigned to this extension point.
  • maximumRedeliveries: The maximum number of redelivery attempts before the message is sent to the dead letter queue.
  • redeliveryDelay: The delay between redelivery attempts, in milliseconds.

registered​

The registered method is invoked when a new customer registers in Cortex. This can happen either due to the Cortex registration resource being called, or due to the Cortex OpenID Connect resource being called for a subject that is not present in the database.

authenticated​

The authenticated method is invoked when a customer logs into Cortex. This can happen either due to the OAuth2 token resource being called for a registered role, or due to the Cortex OpenID Connect resource being called for a subject that is present in the database.

updated​

The updated method is invoked when a customer attribute value is modified.

Extension Sample​

@SuppressWarnings("checkstyle:magicnumber")
@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.CUSTOMER_EVENT, priority = 100)
public class SegmentCustomerEvents extends XPFExtensionPointImpl implements CustomerEvent {

private static final String ATTRIBUTE_KEY_FIRST_NAME = "CP_FIRST_NAME";
private static final String ATTRIBUTE_KEY_LAST_NAME = "CP_LAST_NAME";

@Override
public XPFDeliveryPolicy getDeliveryPolicy() {
XPFDeliveryPolicy xpfDeliveryPolicy = new XPFDeliveryPolicy();
xpfDeliveryPolicy.setConsumerQueueName("segment");
xpfDeliveryPolicy.setMaximumRedeliveries(10);
xpfDeliveryPolicy.setRedeliveryDelay(10000); // 10 seconds
return xpfDeliveryPolicy;
}

@Override
public void registered(final XPFCustomerEventContext context) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFCustomer customer = context.getCustomer();
Map<String, String> traitsMap = new HashMap<>();
traitsMap.put("type", customer.getType().name());
traitsMap.put("email", customer.getEmail());
if (customer.getAttributeValueByKey(ATTRIBUTE_KEY_FIRST_NAME, Locale.ENGLISH).isPresent()
&& customer.getAttributeValueByKey(ATTRIBUTE_KEY_LAST_NAME, Locale.ENGLISH).isPresent()) {
traitsMap.put("name", customer.getAttributeValueByKey(ATTRIBUTE_KEY_FIRST_NAME, Locale.ENGLISH).get().getStringValue()
+ " " + customer.getAttributeValueByKey(ATTRIBUTE_KEY_LAST_NAME, Locale.ENGLISH).get().getStringValue());
}
analytics.enqueue(IdentifyMessage.builder()
.userId(customer.getSharedId())
.traits(traitsMap));
analytics.enqueue(TrackMessage.builder("Customer registered")
.userId(customer.getSharedId())
.properties(ImmutableMap.<String, Object>builder().build()));
}
}

@Override
public void authenticated(final XPFCustomerEventContext context) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFCustomer customer = context.getCustomer();
analytics.enqueue(TrackMessage.builder("Customer authenticated")
.userId(customer.getSharedId())
.properties(ImmutableMap.<String, Object>builder().build()));
}
}

@Override
public void updated(final XPFCustomerEventContext context) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFCustomer customer = context.getCustomer();
Map<String, String> traitsMap = new HashMap<>();
traitsMap.put("type", customer.getType().name());
traitsMap.put("email", customer.getEmail());
if (customer.getAttributeValueByKey("CP_FIRST", Locale.ENGLISH).isPresent()
&& customer.getAttributeValueByKey("CP_LAST", Locale.ENGLISH).isPresent()) {
traitsMap.put("name", customer.getAttributeValueByKey("CP_FIRST", Locale.ENGLISH).get().getStringValue()
+ " " + customer.getAttributeValueByKey("CP_LAST", Locale.ENGLISH).get().getStringValue());
}
analytics.enqueue(IdentifyMessage.builder()
.userId(customer.getSharedId())
.traits(traitsMap));
analytics.enqueue(TrackMessage.builder("Customer updated")
.userId(customer.getSharedId())
.properties(ImmutableMap.<String, Object>builder().build()));
}
}
}