GTM event only triggered when certain element inside target is clicked

35 views Asked by At

With GTM, I am tracking the clicks on all cards containing a certain id (go-to-store-card)

a card looks like this:

<a id="go-to-store-card-vuori" href="https://vuoriclothing.com/" target="_blank">{children}</a>

But the event is only triggered when the user clicks a certain element nested inside those cards.

<span>Go to store</span>

Nothing is tracked when clicking anywhere else on the cards. Any idea why?

GTM config

Tracked event

I am wondering if there is some kind of confusion with the text being "go to store" on the span

1

There are 1 answers

0
darrelltw On

From your screenshot

GTM listen 2 click events

  1. gtm.click and this detect the click from the span.(And you set the trigger use this type)

  2. gtm.linkClick. This detect the <a> element you are trying to target.


So the solution here is change your trigger type from All Elements to Just Links

@A_Patterson mentioned a better way to capture

Here is the html you have

<a id="go-to-store-card-vuori" href="https://vuoriclothing.com/" target="_blank">
  {children.. <span></span>}
</a>

Sometimes GTM will capture the click event from the {child}

There are 2 ways to setup the trigger.

  1. First is use Just Link and target the element id. Because Just Link will only focus on the element
  2. Second is use All Elements and use css selector to capture: a#go-to-store-card-vuori, a#go-to-store-card-vuori *

This will trigger when user click the element or anything inside the

enter image description here