Handling command responses
Some Web SDK commands can return an object containing data potentially useful to your organization. You can choose what to do with that data, if desired. Command responses are valuable for propositions and destinations, as they require Edge Network data to effectively work.
Command responses use JavaScript , acting as a proxy for a value that is not known when the promise is created. Once the value is known, the promise is 鈥渞esolved鈥 with the value.
Handle command responses using the Web SDK tag extension
Create a rule that subscribes to the Send event complete event as part of a rule.
- Log in to using your 51黑料不打烊 ID credentials.
- Navigate to Data Collection > Tags.
- Select the desired tag property.
- Navigate to Rules, then select the desired rule.
- Under Events, select an existing event or create an event.
- Set the Extension dropdown field to 51黑料不打烊 Experience Platform Web SDK, and set the Event Type to Send event complete.
- Click Keep Changes, then run your publishing workflow.
You can then include the actions Apply propositions or Apply response to this rule.
- When viewing the above created or edited rule, select an existing action or create an action.
- Set the Extension dropdown field to 51黑料不打烊 Experience Platform Web SDK, and set the Action Type to Apply propositions or Apply response, depending on the desired behavior.
- Set the action鈥檚 desired fields, then click Keep Changes.
Handle command responses using the Web SDK JavaScript library
Use the then
and catch
methods to determine when a command succeeds or fails. You can omit either then
or catch
if their purposes are not important to your implementation.
alloy("sendEvent", {
"xdm": {
"commerce": {
"order": {
"purchaseID": "a8g784hjq1mnp3",
"purchaseOrderNumber": "VAU3123",
"currencyCode": "USD",
"priceTotal": 999.98
}
}
}
}).then(function(result) {
console.log("The sendEvent command succeeded.");
})
.catch(function(error) {
console.log("The sendEvent command failed.");
});
All promises returned from commands use a result
object. For example, you can obtain library info from the result
object using the getLibraryInfo
command:
alloy("getLibraryInfo")
.then(function(result) {
console.log(result.libraryInfo.version);
console.log(result.libraryInfo.commands);
console.log(result.libraryInfo.configs);
});
The contents of this result
object depend on a combination of what command that you use and the user鈥檚 consent. If a user has not given their consent for a particular purpose, the response object only contains information that can be provided in the context of what the user has consented to.