onBeforeEventSend
The onBeforeEventSend callback allows you to register a JavaScript function that can alter the data you send just before that data is sent to Adobe. This callback allows you to manipulate the xdm or data object, including the ability to add, edit, or remove elements. You can also conditionally cancel the sending of data altogether, such as with detected client-side bot traffic.
Register the onBeforeEventSend callback when running the configure command. You can change the content variable name to any value that you would like by changing the parameter variable inside the inline function.
alloy("configure", {
datastreamId: "ebebf826-a01f-4458-8cec-ef61de241c93",
orgId: "ADB3LETTERSANDNUMBERS@AdobeOrg",
onBeforeEventSend: function(content) {
// Use nullish coalescing assignments to add a new value
content.xdm._experience ??= {};
content.xdm._experience.analytics ??= {};
content.xdm._experience.analytics.customDimensions ??= {};
content.xdm._experience.analytics.customDimensions.eVars ??= {};
content.xdm._experience.analytics.customDimensions.eVars.eVar1 = "Analytics custom value";
// Use optional chaining to change an existing value
if(content.xdm.web?.webPageDetails) content.xdm.web.webPageDetails.URL = content.xdm.web.webPageDetails.URL.toLowerCase();
// Remove an existing value
if(content.xdm.web?.webReferrer) delete content.xdm.web.webReferrer.URL;
// Return true to immediately send data
if (sendImmediate == true) {
return true;
}
// Return false to immediately cancel sending data
if(myBotDetector.isABot()){
return false;
}
// Assign the value in the 'cid' query string to the tracking code XDM element
content.xdm.marketing ??= {};
content.xdm.marketing.trackingCode = new URLSearchParams(window.location.search).get('cid');
}
});
You can also register your own function instead of an inline function.
function lastChanceLogic(content) {
content.xdm.application ??= {};
content.xdm.application.name = "App name";
}
alloy("configure", {
datastreamId: "ebebf826-a01f-4458-8cec-ef61de241c93",
orgId: "ADB3LETTERSANDNUMBERS@AdobeOrg",
onBeforeEventSend: lastChanceLogic
});
Configure on before event send callback using the Web SDK tag extension
These settings can be configured in the Web SDK tag extension using Data collection configuration settings.