Expand my Community achievements bar.

SOLVED

Issues setting DTM Data Element by either returning value or setting data element directly

Avatar

Level 2

I have some listening code that is being served as a custom script for the data element that could make multiple updates per page view which is capturing the value of a HTML5 Custom Attribute. The issue is I can't get listening code to return the value for data element to be set. Not sure what I'm doing wrong and have tried numerous approaches. When ever I check the value of the data element I get the default value that was set in the UI. Any idea how I make the data element update every time a qualifying element is clicked?

function addEvent(el, ev, fn, uc) { if (el.addEventListener) { el.addEventListener(ev, fn, uc); } else if (el.attachEvent) { // IE8- el.attachEvent('on'+ev, fn); } } addEvent(document, 'click', function(e) { e = e || window.event; var target = e.target || e.srcElement; var customLinkName = target.getAttribute("data-analytics-tracking-name"); if(customLinkName){ //return or set customLinkName from attribute; //_satellite.setVar("custom link name", customLinkName); } }, false);
1 Accepted Solution

Avatar

Correct answer by
Level 2

I just found out from a friend that to make this work, whatever data element name I use in the _satellite.setVar function, ensure that it does not exist as a pre-defined data element. It will not allow you to overwrite the definition with the _satellite.setVar function. So I can just add a custom condition to the event rule to dynamically get the value from this attribute that was listening for the attribute click.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 2

I just found out from a friend that to make this work, whatever data element name I use in the _satellite.setVar function, ensure that it does not exist as a pre-defined data element. It will not allow you to overwrite the definition with the _satellite.setVar function. So I can just add a custom condition to the event rule to dynamically get the value from this attribute that was listening for the attribute click.