ÃÛ¶¹ÊÓƵ

onBeforeLinkClickSend

IMPORTANT
This callback is deprecated. Use 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.

WARNING
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 ÃÛ¶¹ÊÓƵ.

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 using your ÃÛ¶¹ÊÓƵ ID credentials.
  2. Navigate to Data Collection > Tags.
  3. Select the desired tag property.
  4. Navigate to Extensions, then click Configure on the ÃÛ¶¹ÊÓƵ 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 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. The onBeforeEventSend callback runs if it contains a registered function.
  • return false: Immediately exit the callback and abort sending data to ÃÛ¶¹ÊÓƵ. The onBeforeEventSend 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.

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
});
recommendation-more-help
ad108910-6329-42f1-aa1d-5920a2b13636