Sourcepoint provides callbacks that you can define within the Preferences messaging code. Please refer to the tables below for more information.
Optional callbacks
The following callbacks can be utilized by your organization to include custom code to be executed in response to keys events in the Preferences messaging flow (e.g. the end-user clicks the cancel button in your Preferences message). A description of the event callback and data returned is described below.
onMessageReady
Event callback fires when a message is about to display. This callback returns the message_type
:
Parameter | Type | Description |
message_type |
String | The category to which the message belongs: preferences
|
onMessageReady: function (message_type) {
console.log('message_type: ' + message_type)
}
onPrefCancel
Event callback fires when a user clicks the Preferences message's cancel button. This callback returns the message_type
:
Parameter | Type | Description |
message_type |
String | The category to which the message belongs: preferences
|
onPrefCancel: function (message_type) {
console.log('message_type: ' + message_type)
}
onMessageReceiveData
This event will always fire and sends data about the message and campaign to the callback.
Note: If a message is not displayed to an end-user, the data
object will only return the messageId
property with a value of 0
.
The callback data returns the following information:
Parameter | Type | Description |
message_type |
String | The category to which the message belongs: preferences
|
data |
Object | Click here for more information on the properties contained in the data object. |
data
object
Property | Type | Description |
messageId |
Number | The message ID. Will return 0 if no message is shown to the end-user |
msgDescription |
String | Name of message in your Sourcepoint portal. |
bucket |
Number | The specific partition bucket (0-999). |
uuid |
String | End-user's profile ID. |
categoryId |
Number | The category ID for the message. Should return 7 which indicates preferences . |
subcategoryId |
Number | The message type ID. Should return 1 which indicates a notice . |
onMessageReceiveData: function (message_type, data) {
console.log('message_type' + message_type);
console.log('prtnUUID: ' + data.prtnUUID);
console.log('messageId: ' + data.messageId);
console.log('messageDescription: ' + data.messageDescription);
console.log('bucket: ' + data.bucket);
console.log('categoryId: ' + data.categoryId);
console.log('subCategoryId: ' + data.subCategoryId);
console.log(JSON.stringify(data));
}
onSPReady
Event callback fires when the Preferences message is ready to be displayed on the page.
onSPReady: function () {
console.log('onSPReady')
}
onError
Event callback fires when an error occurs. This callback function returns message_type
, errorCode
and errorObject
:
Parameter | Type | Description |
message_type |
String | The category to which the message belongs: preferences
|
errorCode |
String | The error code corresponds to one of five string values defined in this table |
error |
Object | This object includes the error stack trace. |
onError: function (message_type, errorCode, errorObject, userReset){
console.log('message_type: ' + message_type);
console.log('errorCode: ' + errorCode);
console.log(errorObject);
console.log('userReset: ' + userReset);
}
The list of error codes passed that can be passed to the onError
callback are:
onError code | Description | Troubleshoot |
ACTION |
Error came from an action. Some possible actions that can cause this error are:
|
|
CHOICE |
Error came from an invalid choice action being provided to the script. |
Error could be due to a malformed message. Try updating the button or link that triggers this error to fix the choice action, or re-save the message. |
REQUEST |
A network error occurred. Some possible reasons that can cause this error are:
Note: In this case the user ID of the individual will be reset. |
Generally, these errors are not fixable but should be rare. |
RENDERING_APP_PM |
Our message renderer has encountered an error while rendering a Privacy Manager message and may be in a bad state. The script will not display the message. |
If this error occurs please contact your Sourcepoint key account manager. |
RENDERING_APP_MESSAGE |
Our message renderer has encountered an error while rendering a message and may be in a bad state. The script will not display the message. |
If this error occurs please contact your Sourcepoint key account manager. |
RENDERING_APP_SIGNATURE |
For preloaded messages, our message renderer encountered an error while trying to validate your message's cryptographic signature. |
If this error occurs please contact your Sourcepoint key account manager. |
UNKNOWN |
Unclassified error occurred. Note: In this case the user ID of the individual will be reset. |
Examine the stack trace in the error provided. If the error persists and is not identifiable, please contact your Sourcepoint representative. |
Example
...
<script>
window._sp_queue = [];
window._sp_ = {
config: {
accountId: ACCOUNT_ID,
baseEndpoint: 'https://cdn.privacy-mgmt.com',
preferences: {
id: 'test@demo.com'
},
propertyHref: 'https://yourexamplehere.com',
events: {
onMessageReady: function (message_type) {
console.log('message_type: ' + message_type)
},
onPrefCancel: function (message_type) {
console.log('message_type: ' + message_type)
},
onMessageReceiveData: function (message_type, data) {
console.log('message_type' + message_type);
console.log('prtnUUID: ' + data.prtnUUID);
console.log('messageId: ' + data.messageId);
console.log('messageDescription: ' + data.messageDescription);
console.log('bucket: ' + data.bucket);
console.log('categoryId: ' + data.categoryId);
console.log('subCategoryId: ' + data.subCategoryId);
console.log(JSON.stringify(data));
},
onSPReady: function () {
console.log('onSPReady')
},
onError: function (message_type, errorCode, errorObject, userReset){
console.log('message_type: ' + message_type);
console.log('errorCode: ' + errorCode);
console.log(errorObject);
console.log('userReset: ' + userReset);
},
}
}
}
</script>
...
Comments
0 comments