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 promises, acting as a proxy for a value that is not known when the promise is created. Once the value is known, the promise is “resolved” with the value.
Create a rule that subscribes to the Send event complete event as part of a rule.
You can then include the actions Apply propositions or Apply response to this rule.
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’s 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.