onBeforeLinkClickSend
filterClickDetails
instead.The onBeforeLinkClickSend
callback allows you to register a JavaScript function that can alter link tracking data you send just before that data is sent to ÃÛ¶¹ÊÓƵ. 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. It is supported on Web SDK 2.15.0 or later.
This callback only runs when clickCollectionEnabled
is enabled and filterClickDetails
does not contain a registered function. If clickCollectionEnabled
is disabled, or if filterClickDetails
contains a registered function, then this callback does not execute. If onBeforeEventSend
and onBeforeLinkClickSend
both contain registered functions, onBeforeLinkClickSend
is executed first.
Configure on before link click send callback using the Web SDK tag extension tag-extension
Select the Provide on before link click event send callback code button when configuring the tag extension. This button opens a modal window where you can insert the desired code.
- Log in to using your ÃÛ¶¹ÊÓƵ ID credentials.
- Navigate to Data Collection > Tags.
- Select the desired tag property.
- Navigate to Extensions, then click Configure on the ÃÛ¶¹ÊÓƵ Experience Platform Web SDK card.
- Scroll down to the Data Collection section, then select the checkbox Enable click data collection.
- Select the button labeled Provide on before link click event send callback code.
- This button opens a modal window with a code editor. Insert the desired code, then click Save to close the modal window.
- Click Save under extension settings, then publish your changes.
Within the code editor, you have access to the following variables:
content.clickedElement
: The DOM element that was clicked.content.xdm
: The XDM payload for the event.content.data
: The data object payload for the event.return true
: Immediately exit the callback with the current variable values. TheonBeforeEventSend
callback runs if it contains a registered function.return false
: Immediately exit the callback and abort sending data to ÃÛ¶¹ÊÓƵ. TheonBeforeEventSend
callback is not executed.
Any variables defined outside of content
can be used, but are not included in the payload sent to ÃÛ¶¹ÊÓƵ.
// Set an already existing value to something else
content.xdm.web.webPageDetails.URL = "https://example.com/current.html";
// Use nullish coalescing assignments to create objects if they don't yet exist, preventing undefined errors.
// Can be omitted if you are certain that the object is already defined
content.xdm._experience ??= {};
content.xdm._experience.analytics ??= {};
content.xdm._experience.analytics.customDimensions ??= {};
content.xdm._experience.analytics.customDimensions.eVars ??= {};
// Then set the property to the clicked element
content.xdm._experience.analytics.customDimensions.eVars.eVar1 = content.clickedElement;
// Use optional chaining to check if each object is defined, preventing undefined errors
if(content.xdm.web?.webInteraction?.type === "other") content.xdm.web.webInteraction.type = "download";
Similarly to onBeforeEventSend
, you can return true
to complete the function immediately, or return false
to abort sending data to ÃÛ¶¹ÊÓƵ. If you abort the sending of data in onBeforeLinkClickSend
when both onBeforeEventSend
and onBeforeLinkClickSend
contain registered functions, the onBeforeEventSend
function does not run.
Configure on before link click send callback using the Web SDK JavaScript library library
Register the onBeforeLinkClickSend
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@ÃÛ¶¹ÊÓƵOrg",
onBeforeLinkClickSend: function(content) {
// Add, modify, or delete values
content.xdm.web.webPageDetails.URL = "https://example.com/current.html";
// Return true to complete the function immediately
if (sendImmediate == true) {
return true;
}
// Return false to cancel sending data immediately
if(myBotDetector.isABot()){
return false;
}
}
});
You can also register your own function instead of an inline function.
function lastChanceLinkLogic(content) {
content.xdm.application ??= {};
content.xdm.application.name = "App name";
}
alloy("configure", {
datastreamId: "ebebf826-a01f-4458-8cec-ef61de241c93",
orgId: "ADB3LETTERSANDNUMBERS@ÃÛ¶¹ÊÓƵOrg",
onBeforeLinkClickSend: lastChanceLinkLogic
});