Search code examples
javascriptanalyticsadobe-analytics

Link Tracking with DTM and Custom Variables


I need to capture the link that was clicked as well as the page that the link was clicked on using Adobe DTM, and then pass it into an evar and sprop. I don't need pageviews, so the s.tl() is used.

I'm using an event based rule with "click" as my event type, with my element tag/selector as "a" for the anchor tag.

Below is the page code that I'm using in DTM - but my problem is, I'm getting an "Unexpected token ILLEGAL (line: 1, col:3)" and I can't seem to figure out why.

Ultimately - is this the right approach to take, or is there a more simplified approach or better solution?

// Custom Link Tracking
$(“a”).click(function(event) {
console.log($(this).text();
s.eVarXX = $(this).text();

Solution

  • By using an event-based rule that already listens for the anchor click you don't need another jQuery function.

    You can simply grab both the href and link text within the Adobe Analytics section of your rule:

    s.prop1 = $(this).text() // link text
    s.eVar1 = $(this).attr("href") // Link URL
    

    Hope this Helps