For the managed package runtime, before the tracking service executes its own logic, it calls any interface implementations named TrackOmniScript or TrackCard, enabling you to preprocess tracking data. For example, this implementation uses the customer ID submitted by an Omniscript to add customer detail to the event data.
This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see Omnistudio Help.
global class VlocityDemoTrackOmniscript implements vlocity_cmt.VlocityOpenInterface {
global Boolean invokeMethod( String methodName, Map<String,Object> inputMap, Map<String,Object> outMap, Map<String,Object> options ) {
Boolean success = true;
string errors = 'OK';
try {
if( methodName == 'processTracking' ){
processTrackingEvent( (List<Map<String, Object>>)inputMap.get('trackingDataList'), outMap );
}
} catch ( Exception e ) {
errors = e.getMessage();
success = false;
System.debug( '##### errors: ' + errors );
}
return true;
}
/**
* Process the tracking events
*/
void processTrackingEvent( List<Map<String, Object>> trackingDataList, Map<String, Object> outMap ){
// Get the current users Id from the input JSON...
Id userId = (Id)trackingDataList[0].get('UserId');
// Get the users details to add to the tracking data...
User currentUser = [SELECT Id, FirstName, LastName, Profile.Name, UserRole.Name FROM User WHERE Id = :userId];
// Iterate through the tracking entries and add the User's details...
for ( Map<String, Object> trackingEvent : trackingDataList ){
trackingEvent.put( 'UserFirstName', currentUser.FirstName );
trackingEvent.put( 'UserLastName', currentUser.LastName );
trackingEvent.put( 'UserProfile', currentUser.Profile.Name );
trackingEvent.put( 'UserRole', currentUser.UserRole.Name );
}
outMap.put( 'trackingDataList', trackingDataList );
}
}