Wuen
Wuen

Reputation: 13

Google Tag Manager Removing some {{Click Text}}

I want to track link clicks so i've set up a tag with the label as {{Click Text}}

However, if I have the following html, it returns "Hello World I dont want this text"

<a href="http://example.com"> 
Hello World 
<span><p> I dont want this text </p></span>
</a>
            

How do I exclude "I dont want this text" from the result?

Thanks

Upvotes: 1

Views: 1323

Answers (1)

Victor Leontyev
Victor Leontyev

Reputation: 8736

I presume that you have a trigger with type Click-Just Links. Then, to achieve only Hello World in your tag you need to do the following:

1) Create Variable:

Type: Custom Javascript

Code: function () {return $({{Click Element}}).clone().children().remove().end().text();}

Name: Click Text Without Children

2) In your trigger, you can use variable {{Click Text Without Children}} which will return only Hello world for you

Upvotes: 2

Related Questions