TheRealPapa
TheRealPapa

Reputation: 4539

Google Tag Manager Click Classes Event not working

I am working with a page that contains an iFrame using a system which seems written by aliens. The system was written many years ago in dotNet framework.

I am trying to track a click event via a tag but I have noticed that when clicking the element in the iFrame, the console shows 2 elements being clicked and Tag Manager shows 2 click events. The first element shown from the click is an element hidden at the top of the page, the second click is the element I clicked.

The HTML is:

<input type="button" name="BOOK NOW" value="Book Now" class="platinum-book-button btn btn-primary">

In Tag Manager I have set up a trigger as follows:

Trigger Type: Click All Elements
Trigger Fires: Some Clicks
Condition: Click Classes - matches CSS Selector - .platinum-book-button .btn .btn-primary

I then add in the console (as `CTRL - Click does not stop page changing):

document.addEventListener('click', function (event) { 
    event.preventDefault(); 
    console.log(event.target); 
}, false);

and console shows:

<input type="submit" name="ctl00$plcBody$BookingFormGrid$ctl04" value="BOOK NOW" onclick="$('form').attr('action', 'DetailsEntry.aspx?bfid=126b48d6-e3b9-4e57-8be6-067da3425467&amp;bfpid=c125f99a-093c-402a-8855-436e7d233d74&amp;bfrtid=bf8acbd4-78a1-4391-9972-3366c5405ce3&amp;arr=2019-07-07&amp;nts=5&amp;a=1&amp;c=0');WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$plcBody$BookingFormGrid$ctl04&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" class="btn btn-primary bnow">

<input type="button" name="BOOK NOW" value="Book Now" class="platinum-book-button btn btn-primary">

The first element is hidden at the top of the page and not the element I have clicked. The trigger does not fire as the click classes condition is not met.

What have I missed?

Upvotes: 4

Views: 7421

Answers (1)

TheRealPapa
TheRealPapa

Reputation: 4539

I ended up using

Trigger Type: Click All Elements
Trigger Fires: Some Clicks
Condition: Click Element - matches CSS Selector - [name="BOOK NOW"]

Upvotes: 5

Related Questions