How to track GTM event once even after the page reloaded - google-analytics

I set up a trigger for the visibility of an element that is located on the page after payment. The problem is that this page automatically reloads every 10 seconds. The trigger fires on every load, which distorts my analytics.
I cannot specify for the tag "Once per event", because the same client can make another order and get to this page (on another day). The page does not have a custom URL, so it only remains to track it by the visibility of a unique element (success icon)
How can I make it so that the event is only registered once, even if the user reloads the page himself or the browser does it automatically?

The simplest thing you could fix it with is by setting a cookie after you send your event. And make a blocking trigger to block it from firing if the cookie is set.
Make sure to set appropriate expiry time for that cookie.
A more complex, but firm implementation would involve your web-dev team. So that the event would rely on the actual payment being sent rather than some page loading or a cookie being there. It should also be fairly easy for the front-end. They just need to add a dataLayer event push to the payment's success callback.

For the event you are capturing on visibility, send the payment id or some sort of id that's unique to that particular payment as part of the event label.
This way all the payments will be captured will have a unique label and you can either count the number of rows for the number of payments OR the "Unique Events" metric (note, if the user is allowed to come back to this page in a new session, then the event will trigger again and the "Unique Events" metric will increment by 1 for that event, so if this is the case, count the number of rows)
Better yet, use e-commerce features in GA and capture this as a transaction.

Related

Triggering a GTM event with Mailchimp pop up form submission

I have the standard Mailchimp pop up embedded on my site. I would like to trigger a GTM event every time it's submitted to send to GA. It's an embedded iframe and I'm not seeing a way to handle this. This is the embed code for the pop up:
<script id="mcjs">!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/xxxx/xxxx.js");</script>
I've tried reviewing the form class, form element and other form triggers, but nothing is triggering the GTM event.
GTM's "Form Submission" trigger cannot catch form submissions in (embedded) iframes.
If you are only interested in the submit, you can add a custom event listener via a "Custom HTML" tag which pushes a custom event to dataLayer which you can then act on in GTM.
document.querySelector('#PopupSignupForm_0 div.mc-modal iframe').contentDocument.querySelector('form').addEventListener('submit', function(event){dataLayer.push({event: 'mailchimp_submit'})});
This triggers every time the "subscribe" button is clicked - also when the form does not validate.
Maybe it is better to use a Timer trigger which checks for a "MCPopupSubscribed" cookie with the value "yes"?
Create a Variable "MCPopupSubscribed", 1st Party Cookie, Cookie Name: "MCPopupSubscribed", Format Value: Convert undefined to "no"
Create a Variable "TimerID", Data Layer Variable, "gtm.timerId", Version 2
Create a Trigger "Mailchimp", Timer, Event Name: "gtm.timer", Interval: 1000, Enable ...: MCPopupSubscribed does not equal yes, Fires on some timers: MCPopupSubscribed equals yes
Create your tag, fires on "Mailchimp" trigger
Create a Tag "Clear Timer", Custom HTML, fires on "Mailchimp" trigger
if ({{TimerID}}) {
window.clearInterval({{TimerID}});
}
The Timer will only "run" if the cookie is absent. It then checks every second if the cookie was set. If it is set it runs your tag and it runs "Clear Timer" to stop the timer/trigger. If it the timer is not stopped the trigger keeps firing every second.
There's also a cookie MCPopupClosed=yes which is set if the user closes the popup...

Events trigger after next click in Google Tag manager preview

My custom event does populate into my GA4 Analytics, but during testing, the events in the GTM preview don't show up until the next click after the triggering event.
Oddly, it seems that after the initial trigger of each event (with the followup click) they appear to
For the follow-up click, I can click anywhere on the page.
The trigger is set to "All Elements" and Firing when the element matches a CSS selector of [data-XXX="XXX"] and the page URL contains a keyword.
I'm concerned that due to the extra click needed I may be losing some non-zero portion of data. My site doesn't get too many of this particular event so every one counts. The event tracks our online reservation and I need it to be accurate in our Google Ads data so our ROI on ad spend is as accurate as possible.
I know there's a trigger on form submit, but the form doesn't actually trigger this way due to JS. And it does work with the "All Elements" trigger I'm just concerned about the extra click before I see it populate in the preview window.
After closer inspection I found that the followup click is not required.
The summary view does not appear to show ALL info for every single click in realtime. Instead if you choose to look into the data for each click as the happen you can see that the events are triggering as intended, but that new events don't always show in the summary view until after the next click registers.
Hopefully, a future GTM update may fix this as it is not intuitive that the summary view would ever not have the most current data.
TLDR: check the view for each click in the GMT preview and don't rely solely on the summary view.

Keeping user properties between events (Google Tag Manager, Google Analytics 4)

I have a question about user properties in Google Analytics 4.
I created 2 events:
The first one is called custom_session_start and it is triggered every time new session started.
The second is called UI_Interaction which is event that triggers every time that the user is clicking on something in the website.
The custom_session_start has some user properties and event parameters his specific tag in GTM.
The UI_Interaction event has only event parameters in his specific Tag.
From what I know the user property should be save unless I change it manually, so if I created some user properties in custom_session_start they also should be appear in UI_Interaction.
However, when I create a report in GA4 the user properties are only set in every custom_session_start event and they are empty in UI_Interaction event.
Is there a way to keep them also when the UI_Interaction occurs?

How to set up a tag to record clicks of sort by categories list of a product page

I am very new to gtm and trying to set up a tag that can record clicks of the sort by categories of all product pages.
Each category page has the sort by (like any other website), it for example has the options:
Price high to low
Price low to high
Date added
Name a-z
Name z-a
What I am trying to do is to be able track how many people click on those individual sort by categories? I am not sure how to go about this, need guidance.
Thanks!
You need to identify the click as it happens and then send the information to GA. So you need this two blocks in GTM: an universal analytics tag as "event" and a trigger which listens for clicks.
If you don't know CSS selectors the most easy way to find the right values for the trigger is by try and error. Activate the GTM debug mode and navigate to your list.
Now click on the sorting feature, does a click appears in the GTM debug console (the one you see in the lower part of your page)? If no click appears you need to activate at least one trigger which simply listens for any clicks that happen on your page. Now when you see clicks in your GTM debug console: select the click (in "summary" tab of gtm debug console) which appeared when you sorted. Now when the click is selected in summary the "variables" tab will show you all values within your defined variables.
All click variables should be activated in GTM. Then you can see what information is hold in them, when the user sorts.
As you now know the values of your variables when the sort action appears, you should use this information to create a trigger (something like: click element contains "xyz") and an universal analytics event which will send event category, action and label (one of these should contain information on click element) to Google Analytics as soon as your trigger is activated.

Bounce rate in Google Analytics

I have website in which when a user land on the website(say xyz.com) . Website open with a pop up(no tracking is enable on the popup) and user cannot perform any action unless it closes the pop up and also the page is not reloaded after closing the pop up
below are my queries.
1) No tracking enable on pop up close
If user doesn't visit any more pages in the website post closing the pop up. But perform different action on same page (such as check box selection ,drop down selection) on which event are define. do still this page will be calculated as bounce page and visit will be calculated as bounce visit?
2) Tracking enable on pop up close .
If user doesn't visit any more pages in the website post closing the pop up. But perform different action on same page(such as check box selection ,drop down selection) on which event are define. do still this page will be calculated as bounce page and visit will be calculated as bounce visit?
3) Tracking enable on pop up close
Post closing pop up user doesn't perform any activity.
do still this page will be calculated as bounce page and visit will be calculated as bounce visit?
A bounce is a visit with only one interaction.
If both your site and the popup have tracking code that's two interactions and the visitor will not be counted as a bounce.
In the case of events it depends. You can set a flag in your event tracking code that determines if the event affects the bounce rate. By default an event will count as interaction, and a user with a pageview and an event will not count as bounce. However if you set the "noninteraction" flag to "true" the event will not be counted towards the bounce rate (i.e. somebody who has only one pageview and one or multiple event hit will still count as a bounce).
So for your examples, and any other use cases you can come up with, simply count the numbers of interactions that do not have a non-interaction flag set (and adjust your tracking code according to your use case). If the number is larger than 0 the visit will not be counted as a bounce.

Resources