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 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. It is supported on Web SDK 2.15.0 or later.

This callback only runs when clickCollectionEnabled is enabled. If clickCollectionEnabled is disabled, this callback does not execute. If both onBeforeEventSend and onBeforeLinkClickSend contain registered functions, the onBeforeLinkClickSend function executes first. Once the onBeforeLinkClickSend function finishes, the onBeforeEventSend function then executes.

This callback allows the use of custom code. If any code that you include in the callback throws an uncaught exception, processing for the event halts. Data is not sent to Adobe.

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.

  1. Log in to experience.adobe.com using your Adobe ID credentials.
  2. Navigate to Data Collection > Tags.
  3. Select the desired tag property.
  4. Navigate to Extensions, then click Configure on the Adobe Experience Platform Web SDK card.
  5. Scroll down to the Data Collection section, then select the checkbox Enable click data collection.
  6. Select the button labeled Provide on before link click event send callback code.
  7. This button opens a modal window with a code editor. Insert the desired code, then click Save to close the modal window.
  8. Click Save under extension settings, then publish your changes.

Within the code editor, you can add, edit, or remove elements within the content object. This object contains the payload sent to Adobe. You do not need to define the content object or wrap any code within a function. Any variables defined outside of content can be used, but are not included in the payload sent to Adobe.

The objects content.xdm, content.data, and content.clickedElement are always defined in this context, so you do not need to check if they exist. Some variables within these objects depend on your implementation and data layer. Adobe recommends checking for undefined values within these objects to prevent JavaScript errors.

For example, say you want to perform the following actions:

  • Modify the current page URL
  • Capture the clicked element in an Adobe Analytics eVar
  • Change the link type from “other” to “download”

The equivalent code within the modal window would be the following:

// 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 immediately complete the function, or return false to immediately cancel sending data. If you cancel the sending of data in onBeforeLinkClickSend when both onBeforeEventSend and onBeforeLinkClickSend contain registered functions, the onBeforeEventSend function does not run.

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", {
  "edgeConfigId": "ebebf826-a01f-4458-8cec-ef61de241c93",
  "onBeforeLinkClickSend": function(content) {
    // Add, modify, or delete values
    content.xdm.web.webPageDetails.URL = "https://example.com/current.html";

    // Return true to immediately complete the function
    if (sendImmediate == true) {
      return true;

    // Return false to immediately cancel sending data
      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", {
  "edgeConfigId": "ebebf826-a01f-4458-8cec-ef61de241c93",
  "onBeforeLinkClickSend": lastChanceLinkLogic