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 conjunction with the Server Side Visitor Profile API, maintains a local copy of the visitor profile throughout the life time of the application.
Data Collection API's are exposed from NuanceProfileManager class.
NuanceProfileManager
To get the instance of NuanceProfileManager class, invoke
NuanceProfileManager.getInstance()
Public Properties
The following public methods are exposed from the NuanceProfileManager class.
-
-(void)addUniqueCustomerID:(NSString*)type andValue:(NSString*)value;
Sets the unique customer ID's that will be used by the startSession API method to find or create profile associated with the current user of the application. This method, and 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.
-
-(void)startSession:(NSString*)siteID andApplicationID:(NSString*)appID andInterval:(enum DCSyncInterval)interval andCompletionHandler:(void (^)(ProfileResponse* success, Response *error))completionBlock
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.
-
-(void)sendCustomEvent:(DataCollectionEvent*)customEvent
Sends new Custom Event regarding the user behaviour.
-
-(void)sendConversionEvent:(ConversionEvent*)conversionEvent
Invoke this API method when ever there is a converstion occurs in the Application.
DataCollectionEvent
Use the DataCollectionEvent convenience class to construct the attributes needed for an event. Pass the instance of this class to the sendCustomEvent API method
You should not directly instantiate DataCollectionEvent class. Instead use init method with a block parameter, which returns an instance of DataCollectionEvent class.
Public Methods
-
- (instancetype)initWithBlock:(DataCollectionEventBuilderBlock)block;
Use the builder parameter provided in the block to set the attributes need for the custom event.
DataCollectionEventBuilder
Public Methods
-
- (void) addCustomEvent:(NSString*)name andValue:(NSString*)value andType:(enum DCCustomEventType)type andAction:(enum DCCustomEventAction)action andIsUnique:(NSString*)unique;
name: Set the name of the attribute associated with this event.
value: Set the value of the above named attribute.
type: Set the type of the above named attribute. Possible attribute types : CustomEventType_ENGAGEMENT,CustomEventType_APPLICATION,CustomEventType_VISITOR.
action: Set the action value of the above named attribute. Possible values are CustomEventAction_APPEND,CustomEventAction_SET and CustomEventAction_REMOVE
unique: Is above named attribute is a unique customer ID.Possible values are yes , no
-
- (void) addCustomVariable:(DCCustomVariable*)customVariable;
Pass an instance of the customVariable class which contains custom variables associated with the event.
DCCustomVariable
DCCustomVariable convenience class provides a way to add custom variables associated with a particular event attribute.
You should not directly instantiate DCCustomVariable class. Instead use init method with a block parameter, which returns an instance of DCCustomVariable class.
Public Properties
-
- (instancetype)initWithBlock:(CustomVariableBuilderBlock)block;
Use the builder parameter provided in the block to set the custom variables associated with the custom event.
CustomVariableBuilderBlock
Public Methods
-
- (void) addCustomVariable:(NSString*)name andValue:(NSString*)value andAction:(enum DCCustomVariableAction)action andPersistenceState:(enum DCCustomVariablePersistence)persistence;
name: Set the name of the Custom variable.
value: Set the value of the above named Custom variable.
action: Set the action value of the above named Custom variable. Possible values are CustomVariableAction_APPEND,CustomVariableAction_SET and CustomVariableAction_REMOVE.
persistence: Set the persistance state of the above named Custom variable. Possible values are CustomVariablePersistence_VOLATILE, and CustomVariablePersistence_PERSISTENT
ConversionEvent
SDK provides ConversionEvent convenience class to construct conversion event object. Pass the instance of this class to the sendConversionEvent API method
You should not directly instantiate ConversionEvent class. Instead use init method with a block parameter, which returns an instance of ConversionEvent class.
Public Properties
-
- (instancetype)initWithBlock:(ConversionEventBuilderBlock)block;
Use the builder parameter provided in the block to set the conversion attributes associated with the event.
ConversionEventBuilderBlock
Public Methods
-
-(void)addConversionEvent:(NSString*)productName andProductCount:(NSInteger)count andProductType:(NSString*)type andProductValue:(CGFloat)value andProductAttrs:(NSDictionary<NSString*,NSString*>*)productAttr;
productName: SetSet the name of the product
count: Set the product count.
type: Set the product type.
value: Set the value/cost of the product
product attrs:List of product attributes to be associated with this product.
-
-(void)addConversionAttributes:(NSString*)name andValue:(NSString*)value;
List of any name/value pairs that you want to associate to this conversion.
-
-(void)addOrderID:(NSString*)orderID;
Unique identifier for this order.
-
-(void)addOrderType:(NSString*)orderType;
Client provided order type to be associated to this order
-
-(void)addCustomEventAttrs:(DataCollectionEvent*)customEvent;
List of any modifiable name/value attributes that you want to associate to this customer, engagement or session.
let customVariable = DCCustomVariable.init(block: { (builder) in
builder?.addCustomVariable("test1", andValue: "true", andAction: CustomVariableAction_SET, andPersistenceState: CustomVariablePersistence_PERSISTENT);
builder?.addCustomVariable("test2", andValue: "value3", andAction: CustomVariableAction_APPEND, andPersistenceState: CustomVariablePersistence_PERSISTENT);
builder?.addCustomVariable("test3", andValue: "value4", andAction: CustomVariableAction_APPEND, andPersistenceState: CustomVariablePersistence_PERSISTENT);
})
let customEvent = DataCollectionEvent.init(block: { (builder) in
builder?.addCustomEvent("email", andValue: "ppp@att.com", andType: CustomEventType_VISITOR, andAction: CustomEventAction_APPEND, andIsUnique: "yes")
builder?.addCustomEvent("email", andValue: "ppp@att.com", andType: CustomEventType_VISITOR, andAction: CustomEventAction_REMOVE, andIsUnique: "yes")
builder?.add(customVariable)
});
NuanceProfileManager.getInstance().sendCustomEvent(customEvent)