Tip:
Highlight text to annotate it
X
Creating a Custom Macro in Google Tag Manager is pretty easy.
While, Google Tag Manager comes with a number of pre-defined macros,
we're going to create a new macro to extract the text of a DOM element,so we can store
the anchor text of a link in a Google Analytics event.
To be consistent we'll call this new macro: element text
For the macro type, we'll select Custom Javascript. Then we'll create an anonymous function that
returns the text of a given DOM element. Since Google Tag Manager allows you to call
existing macros as if they were proper objects, in our return statement we use the element
macro to get the DOM object and then we call the textContent property on it.
We simply save and now we have a new macro that can capture the text of any given DOM
element.