Can override the default data layer elementUrl / Click Url attributes for a span element?

Can I override the default data layer event attributes? I unfortunately have a clickable over layered:

<span class="link__hot-zone"></span>

that covers the <a> and want to add “id” and the other attributes to populate the default data layer props better especially elementId and elementUrl.

Are "data-mtm-click-url" and “data-mtm-click-name” still usuable? I know if I add “id” to the span it will flow through just need to flow through the url on a span element.

Here is my sample data layer:

{
  "event": "stg.capturingClick",
  "element": "body > div > main > div > section > div > div > div > div > article > div > div > header > h3 > a > span",
  "elementId": "",
  "elementClasses": "link__hot-zone",
  "elementUrl": "undefined",
  "gtm.uniqueEventId": 999
}

When I set the id I see that flow through I just need to figure out what the elementurl can be mapped to flow that through:

<span id="test1" class="link__hot-zone"></span>

{
  "event": "stg.capturingClick",
  "element": "body > div > main > div > section > div > div > div > div > article > div > div > header > h3 > a > span#test1",
  "elementId": "test1",
  "elementClasses": "link__hot-zone",
  "elementUrl": "undefined",
  "gtm.uniqueEventId": 998
}

I have tried the following on my span element and no luck yet:

data-elementurl
data-element-url
data-pp-element-url
data-mtm-element-url
src
href

Going down the route of checking if a custom user defined variable is the solution for this until support reaches out to me: https://help.piwik.pro/support/tag-manager/about-user-defined-variables

Ok my solution involved adding a custom JS variable in the Tag Manager:

// Name: Get All Attributes and Data From Clicked Element
function() {
  var element = {{ Click Element }};

  if(!element || element.length == 0) {
    return '{}';
  }

  var attributes = element.attributes;
  var result = [];

  for(var i = 0; i < attributes.length; i++) {
    var attr = attributes[i];
    result.push("'" + attr.name + "':'" +attr.value + "'");
  }

  return "{" + result.join(",") + "}";
}

and referencing that in the Tag “name”:

{{ Get All Attributes and Data From Clicked Element }}

so it flows into the variables data ie:

Get All Attributes and Data From Clicked Element
“{‘id’:‘sadfsad’,‘data-element-url’:‘https://www.google.test’,‘data-url’:‘urltesrt133’,‘class’:‘link__hot-zone’}”

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.