Use Variables in Custom JavaScript Variable

You can simply use the TagManager object, e.g.

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

Will store the value of the attribute “data-name” of the clicked element.