jennEDVT
jennEDVT

Reputation: 739

Google Tag Manager Custom Event not firing

I'm fairly new to Google Tag Manager and am trying to set up my first custom event.

In my html I have, in the very top of my head:

<script>
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({"event": "testEvent"});
</script>

And in Google Tag Manager, I've created a trigger that uses my "testEvent":

enter image description here

Additionally, I've created a tag that uses this custom event:

enter image description here

Lastly, when I debug I see that both my custom event and tag show up:

enter image description here

However, when I click on the DOM element that is supposed to trigger that custom event, nothing happens.

I have tried swapping out my custom event trigger for just the built-in click trigger and that works fine, so that tells me that I have my tag itself set up correctly.

Am I missing a step? Is there something more I need to do to make a custom event work? Like I said, I know I could use a regular click trigger in this test case, but in my actual project, I cannot just use the regular click trigger.

Thanks for any help you can offer!

Upvotes: 0

Views: 10535

Answers (3)

GTM Guy
GTM Guy

Reputation: 46

You need to add the element clicks using JQuery or any other language, as well as change the trigger to fire on "All Custom Events"

for example say I have a chat button

<script>
  var dataLayer = dataLayer || [];
   $('.chatBtn').click(function (e) {
    dataLayer.push({
      'event': 'chat-click'
    });
  });
</script>

The event should be on that particular element click .

Looking at your custom event it is not attached to any element click

Upvotes: 0

uda
uda

Reputation: 136

If your custom event is pushed only for "search_input" clicks, then you can the modify your trigger to "All Custom Events"

else as @GTMGuy said you need to push the event on "search_input" click event.During event trigger in GTM preview, click on the event and check the value of Variables - "Click element" whether it matches your trigger condition.

Upvotes: 0

XTOTHEL
XTOTHEL

Reputation: 5208

it is a configuration issue. If I understand correctly, you're trying to trigger an event tag when someone clicks on an element with a specific css class.

To achieve this, you will need to:

  1. Go to the "Variables" screen in GTM. On the top portion of the screen, there is the "Built-in Variables" section. Click on the "CONFIGURE" button, a side menu should pop up. Look for the "Click Classes" under the "Clicks" section. Check the checkbox beside "Click Classes", close this menu, should show now see the "Click Classes" variable name under "Built-in Variables".

  2. Go to the "Triggers" screen in GTM. Create a new trigger of the type "All Elements" under the "Click" section. When the configuration for this trigger comes up, select "Some Clicks" under "This trigger fires on". You should see 3 input fields come up for the condition of this trigger. In the first select box, you should see "Click Classes" as one of the available selections, pick that. In the next box, select the appropriate comparison type, we will choose "equals" in this case. In the last input box, put in "search__input" or the name of the css class you want to trigger on.

  3. Go back to the "Tags" screen in GTM. Add this trigger to the tag you want and voila!

Upvotes: 1

Related Questions