Google Tag Manager macro for text on page in h1 -
how can add together macro google tag manager text of in class="content" div shown here:
<article class="content"> <h1>meeting of committee</h1> i'm trying set analytics event take text of h1 , set event label. action of event clicking button elsewhere on page. this:
category: meeting action: add together calendar label: meeting of committee
i should note (annoyingly), there multiple h1s on page, targeting ".content h1" me text need. don't know how value macro.
any help much appreciated. thanks!
since h1 not clicked element not automatically stored in macro.
so might create macro of custom javascript type next function:
function() { homecoming window.document.getelementsbytagname('h1')[0].innertext; } this extracts text first h1 on page (ideally there 1 h1) , returns it.
you might want add together error checking in case there no h1, plus there give-and-take if innertext should used (here post differences between innerhtml, innertext, textcontent etc), far can tell innertext works reasonably well.
google-tag-manager
No comments:
Post a Comment