Data Collection API
The Nuance Messaging SDK includes APIs to track visitor behavior in the Native App. These APIs provide a way for enterprise applications to pass custom events regarding the user's behavior. The data passed in these APIs will be used to persist data in a server-side visitor profile. It can retain a single profile for a single customer across multiple devices.
The Data Collection API in conjuction with the Server Side Visitor Profile API maintains a local copy of the visitor profile through out the life time of the application.
ProfileManager
To get the instance of ProfileManager class, invoke
ProfileManager.getInstance()
Public Methods
The following public methods are exposed from the ProfileManager class.
-
public void setUniqueCustomerId(String type, String value)
Sets the unique customer ID's that will be used by the startSession API method to find the profile associated with the current user of the application. This method, in conjuction with startSession, must be invoked immediately after the application launches.
type: Type of the customer ID, for example email or phone.
value: Value for the given type.
-
public void startSession(final String siteID, final String appId, Interval interval , final OnSuccessListener
success, final OnErrorListener errorListener) This method must be invoked prior to calling other DataCollection API method from this class. Start session marks the begining of the user visit to the application. This method also fetches the latest visitor profile from Nuance Visitor Profile server. It is recommended to call this method once immediately upon the application launch.
siteId: Set the siteId value.
appId: Set the application Id.
interval: Set the interval at which data collection API syncs with the server.
-
public void sendCustomEvent(DCEvent.AttributeBuilder builder)
Sends new Custom Event regarding the user behaviour.
-
public void sendConversionEvent(ConversionEvent.ConversionBuilder builder)
Invoke this API method when ever there is a converstion occurs in the Application.
-
public void sendExposedEvent(ExposedEvent.ExposedEventBuilder builder)
This API must be called when ever Messaging UI is displayed to the user.
-
public void flushEvents()
Invoke this method within the currently displayed Activity onStop method. This will let SDK to flush the remaining data collection events from this activity.
SDK provides AttributeBuilder convenience class to construct the attributes of an event.
AttributeBuilder
Create Builder instance by calling Event.builder()
Public Methods
You can use the following builder public methods to construct the attributes comprising a custom event Object. Builder exposes its public method in such a way that you cannot invoke Builder instance build method until calling all of the required fields. You can add more than one attribute in the same event object.
-
public AttributeValue addName(String name)
Set the name of the attribute associated with this event.
-
public AttributeType addValue(String value)
Set the value of the above named attribute.
-
public AttributeAction addType(Type type)
Set the type of the above named attribute. Possible attribute types : ENGAGEMENT_ATTRIBUTE,APPLICATION_ATTRIBUTE,VISITOR_ATTRIBUTE
-
public AttributeBuilder addAction(Action action)
Set the action value of the above named attribute. Possible values are APPEND,SET and REMOVE
-
public AttributeBuilder isUniqueCustomerID(UniqueID unique)
Is above named attribute is a unique customer ID.
-
public AttributeBuilder addCustomVariable(CustomVariable.CustomVariableBuilder builder)
Set any custom variables associated with above named attribute.
CustomVariableBuilder convenience class provides a way to add custom variables associated with a particular event attribute.
CustomVariableBuilder
Create Builder instance by calling CustomVariable.builder()
-
public VariableValue addName(String name)
Set the name of the Custom variable.
-
public VariableValue addValue(String value)
Set the value of the above named Custom variable.
-
public VariableValue addAction(Action action)
Set the action value of the above named Custom variable. Possible values are APPEND,SET and REMOVE
-
public VariableValue addPersistenceState(State state)
Set the persistance state of the above named Custom variable. Possible values are VOLATILE and PERSISTENT
SDK provides ConversionBuilder convenience class to construct conversion event object.
ConversionBuilder
Create Builder instance by calling ConversionEvent.builder()
-
public ProductCount addProductName(String name)
Set the name of the product.
-
public ConversionBuilder addCount(int count)
Set the product count.
-
public ConversionBuilder addType(String type)
Set the product type.
-
public ConversionBuilder addValue(double value)
Set the value/cost of the product.
-
public ConversionBuilder addProductAttrs(String name, String value)
List of product attributes to be associated with this product.
-
public ConversionBuilder addConversionAttrs(String name, String value)
List of any name/value pairs that you want to associate to this conversion.
-
public ConversionBuilder addOrderId(String orderId)
Unique identifier for this order.
-
public ConversionBuilder addOrderType(String type)
Client provided order type to be associated to this order
-
public ConversionBuilder addOtherDCAttrs(DCEvent.AttributeBuilder builder)
List of any modifiable name/value attributes that you want to associate to this customer, engagement or session.
SDK provides ExposedEventBuilder convenience class to construct exposed event object.
ExposedEventBuilder
Create Builder instance by calling ExposedEvent.builder()
-
public ExposedEventBuilder addBusinessRuleID(String brID)
Set the business Rule ID.
-
public ExposedEventBuilder addBusinessUnitId(String agID)
Set the business Unit ID.
-
public ExposedEventBuilder addAgentGroupID(String agID)
Set the agent Group ID.
-
public ExposedEventBuilder addDCAttrs(DCEvent.AttributeBuilder builder)
List of any modifiable name/value attributes that you want to associate to this customer, engagement or session.
NuanMessaging.getInstance().getProfileManager().setUniqueCustomerId("email", "testssvp@att.com");
NuanMessaging.getInstance().getProfileManager().startSession("10003715", "ssvp test app", ProfileManager.Interval.THIRTY_SECONDS, new OnSuccessListener() {
@Override
public void onResponse(ProfileResponse response) {
System.out.println("Session created");
NuanMessaging.getInstance().getProfileManager().sendCustomEvent("onAnyEvent",DCEvent.builder().addName("email").addValue("test1@gmail.cm").
addType(CustomEvent.Type.VISITOR_ATTRIBUTE).addAction(CustomEvent.Action.APPEND).isUniqueCustomerID(CustomEvent.UniqueID.YES));
NuanMessaging.getInstance().getProfileManager().sendCustomEvent("onPageLanding",DCEvent.builder().addName("phone").addValue("1234567").
addType(CustomEvent.Type.APPLICATION_ATTRIBUTE).addAction(CustomEvent.Action.SET).addCustomVariable(CustomVariable.builder().addName("cust1").addValue("custval1").addAction(CustomVariable.Action.APPEND)));
NuanMessaging.getInstance().getProfileManager().sendConversionEvent(ConversionEvent.builder().addProductName("samsung").addCount(2).addValue(100).addProductAttrs("test1","test2").addOrderId("1000")
.addConversionAttrs("con1","con2").addOtherDCAttrs(DCEvent.builder().addName("test").addValue("val").addType(Event.Type.APPLICATION_ATTRIBUTE).addAction(Event.Action.APPEND)));
}
}, new OnErrorListener() {
@Override
public void onErrorResponse(Response response) {
}
});