Dynamic values in custom link

Avatar

Avatar

dustinwallace

Avatar

dustinwallace

dustinwallace

15-02-2018

I am trying to populate the value from the data-id attribute in the link clicked into the custom link, but it just shows %this.data-id% in the actual text in the pev2 value instead of replacing it with the value itself. Are not all dynamic references available in the Custom Link field?

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar

joshd7227840

MVP

Avatar

joshd7227840

MVP

joshd7227840
MVP

15-02-2018

data attributes are special attributes that are found within the dataset object of an element.

So for example, if you have this link:

<a href="somepage.html" data-id="some id">some page</a>

(with pure javascript) you can get the value like so:

var a = document.querySelector('a');

console.log ( a.dataset.id ); // output: "some id"

Alternatively, you can use the elem.getAttribute() method, like so:

var a = document.querySelector('a');

console.log ( a.getAttribute('data-id') ); // output: "some id"

DTM's percent syntax does not let you do the former; it will only let you reference %this.foo% properties that are direct, top level properties of the element.  However, DTM does let you use getAttribute, so you can do this:

%this.getAttribute(data-id)%

Note: Unlike the pure javascript example above, for DTM's percent syntax, you should NOT wrap data-id in quotes.