How to get data attribute in Custom JavaScript variable?

You can use the dataLayer to access the clicked element:

function () {
 if (TagManager.dataLayer.get('mtm.clickElement')) {
     return TagManager.dataLayer.get('mtm.clickElement').getAttribute('data-foo');
 } else { 
     return '';
 }
}

Worked for me :slight_smile:

1 Like