Track links

Links can be set manually or tracked automatically. Manual tracking is done by adding the details under the web.webInteraction part of the schema. There are three required variables:

  • web.webInteraction.name
  • web.webInteraction.type
  • web.webInteraction.linkClicks.value
alloy("sendEvent", {
  "xdm": {
    "web": {
      "webInteraction": {
        "linkClicks": {
            "value": 1
        }
      },
      "name": "My Custom Link", // Name that shows up in the custom links report
      "URL": "https://myurl.com", // The URL of the link
      "type": "other" // values: other, download, exit
    }
  }
});

The link type can be one of three values:

  • other: A custom link
  • download: A download link
  • exit: An exit link

These values are automatically mapped into Adobe Analytics if configured to do so.

Automatic link tracking

By default, the Web SDK captures, labels, and records clicks on qualifying link tags. Clicks are captured with a capture click event listener that is attached to the document.

Automatic link tracking can be disabled by configuring the Web SDK.

clickCollectionEnabled: false

Automatic link tracking is done for anchor A and AREA tags. However, these tags aren’t considered for link tracking if they have an attached onclick handler.

Links are labeled as a download link if the anchor tag includes a download attribute or if the link ends with a popular file extension. The download link qualifier can be configured with a regular expression:

downloadLinkQualifier: "\\.(exe|zip|wav|mp3|mov|mpg|avi|wmv|pdf|doc|docx|xls|xlsx|ppt|pptx)$"

Links are labeled as an exit link if the link target domain differs from the current window.location.hostname.

Links that do not qualify as a download or exit link are labeled as “other.”

The data collected with automatic link tracking can be inspected and filtered by providing an onBeforeEventSend callback function.

Filtering link tracking data can be useful when preparing data for Analytics reporting. Automatic link tracking captures both the link name and link URL. In Analytics reports, the link name takes priority over link URL. If you wish to report the link URL, the link name needs to be removed. The following example shows an onBeforeEventSend function that removes the link name for download links:

alloy("configure", {
  onBeforeEventSend: function(options) {
    if (options
      && options.xdm
      && options.xdm.web
      && options.xdm.web.webInteraction) {
        if (options.xdm.web.webInteraction.type === "download") {
          options.xdm.web.webInteraction.name = undefined;
        }
    }
  }
});

On this page