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

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.”

On this page