0

I have a website and setup GA4 with Google Tag Manager setup. In the GTM, I created a trigger and an event to get recorded in the GA4. I can see that event in my analytics dashboard.

I want to get the name of the event in my front-end whenever an event is triggered. I need it on my front-end to keep count of event history, to further process them. Is there anyway to get the name of the event?

Please let me know how can this be achieved.

What I tried so far:

  • Create a new tag with all the triggers, which has a custom HTML
<script>
  var eventHistory = JSON.parse(localStorage.getItem("eventHistory"));
  if(eventHistory == null) eventHistory = [];
  eventHistory.push(dataLayer.slice(-1)[0].event);
  localStorage.setItem("eventHistory", JSON.stringify(eventHistory));
  console.log(dataLayer.slice(-1)[0].event);
</script>

With this it is only storing gtm.click or gtm.scrollDepth or gtm.dom events, but not the actual event names I set in the tag manager.

I was expecting: the actual event names like add_to_cart, checkout and event names like that.

1 Answer 1

1

I am not sure that you can get the event name, because it's a network request to Analytics. So, I have good idea if you use Tag Manager. In Tag Manager you can create tag "Custom HTML" where you can write simple script which set in Local/Session Storage event name, and you can get it from storage use other script. Trigger for this "Custom HTML" tag is the same for GA4 Event tag (page_view for example). And when this event fire tag with script will be run and set event name to Local/Session Storage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.