Single Page Applications and Google Tag Manager - google-tag-manager

I have a client who wants a tag to fire on a thank you page but have users come from a form fill on a previous page. I've tried all types of set ups but none of them work 100 percent. The only thing I know is that the client site is a single page application which does not support the refer variable. The option that semi-worked leverages the history change trigger type however the client needs to track people who uniquely submitted the form fill page and made it to the thank you page.

The best option here would be adding a dataLayer.push to the successful form submission callback. That is, if the form is submitted via JS.
If it's just a standard (legacy) html form submission, then GTM has listeners for those. But they're rare, especially on SPAs.
If adding a dataLayer.push seems too complex, well then use the thank you page (with the history change) in conjunction with a short-lived cookie to prevent double firing, but it's a hack and not without bugs.

Related

Google Tag Manager - GTM Data layer problems

I've installed the GTM code on a HTML5 bootstrap 5 template, the GTM container and a analytics global site tag added to GTM appear to load and initialise the DOM fine within the GTM preview/debug. The analytics tag pushes click data and the limited event data to the analytics console without issue.
The problem is with GTM variables. In debug mode the loaded GTM container picks up scroll and page events and sets the associated variables but in the case of form data layer variables it has set them once while in debug/preview mode during a newsletter form submission, but doesn't seem to want to set them again in different later debug sessions.
The template in use is:
https://www.okler.net/previews/porto/9.1.0/demo-digital-agency-2-dark.html
The developer doesn't want to offer support for GTM or GA so I was wondering if anyone could see an issue with why the newsletter signup at the end of the page for example that wouldn't set the form data layer variables as expected within GTM when filled and submitted.
Cheers
So you're saying that it pushes the dataLayer event only once per form submission and not more?
Is there a value of tracking multiple form submissions for one user?
If there is enough value to bother fixing it, you can just consider either finding how they prevent subsequent form tracking and fix it, or you can just have custom tracking in GTM. So that you would be able to detect CTA clicks.
But tracking CTA clicks instead of actual form submissions will lead to the opposite problem: too many CTA clicks.
Basically, you have to understand why you're tracking it. What question is to be answered here. In this case the obvious question is whether a user converted. To answer this question, you actually don't need subsequent submissions tracking.
If the question here is how many times the user submitted the form, then simple CTA tracking plus error tracking will suffice. It's not connected to form submissions tracking tho. Different questions - different answers.

Why GTM restirct tag deployment doesnt work

I'm currently working on blocking the scripts injected by gtm and I noticed there's a way to add allowlist or blocklist inside datalayer to reach that: https://developers.google.com/tag-manager/web/restrict
But after trying to add the gtm.allowlist/blocklist, it still injects the 3rd party scripts
Anyone who had any experience on that? Many thx
The best way to allow the delivery of a tag is to associate the correct trigger based on the classification of the cookies you assign.
With OneTrust (you are using) the cookie (or the OnetrustActiveGroups variable) that contains the information of the accepted cookie classes will contextually contain the values ​​C0001, C0002, c0003, C0004, ... If for example the category C0004 is for cookies may be set through our site by our
advertising partners, to GTM Facebook tags, Ads tags, etc ... you will assign as a trigger the check that in that variable there is that value. If it is present the tag is fired otherwise not.
In this way everything is much more controlled and you leave nothing to chance or to the interpretation of the tool.

Adding Custom Popups using google tag manager

When a user lands on a page, I want to show a custom HTML popup. I have Google Tag Manager integrated with the website.
Can this HTML Popup be shown using Google Tag Manager? (script and code to be inserted using Google Tag Manager)
Is it frowned upon / not advised to use google tag manager for
anything apart from tracking?
1.) Yes - GTM is pure Javascript, and inserts Javascript into the page code, so anything you can do you can do via GTM. There are some minor caveats (e.g. a size restriction on custom HTML tags), but doing a popup should work just fine.
2.) There are certain use cases that are discouraged - Google recommends against (or at least used to) making visible changes to the page markup via GTM. The problems with that are that GTM is loaded asynchronously, so you would not know at which point the changes show up and you might get "flickering" pages, and a possible performance impact when you force the page to re-render.
Nothing of this applies to popups, so you should be fine (although using popups these days might have its own problems, but these are not related to GTM).
Personally I would recommend against implementing popups via GTM if the popup is an integral part of your page; splitting up an application between page code and GTM code will sooner or later confuse a developer. But if this is just advertising or a call to action or something similar then (IMO) using GTM is not a problem at all.

Preventing an iframe on the same domain from triggering a page exit in Google Analytics

I am working on a third party website that contains a web application embedded in an iframe on the home page. This iframe is hosted on the same same sub/domain.
Currently page views are being tracked with _trackPageview. Due to a requirement by marketing both pages use the same Google account Id.
Since the iFrame was implemented the marketing department has noticed that the bounce rate has dropped to almost nothing. I suspect that this is because Google is interpreting the pageView event on the iframe as the visitor hitting another page on the website.
Just for additional information, the domain of the _gaq object is being set to "none" for both the container page and iframe.
Does Google provide a mechanism by which you can trigger PageView in such a way that it isn't interpreted as subsequent pageview in this scenario? (I know that trackEvent has a noninteraction property to deal with this?)
Am I better off just disabling the PageView for the default iframe page?
Does Google provide a mechanism - apparently yes, but probably not for your use case.
The field documentation for Universal Analytics describes the non-interaction field thusly:
Specifies that a hit be considered non-interactive.
So in UA this does no seem limited to events but to apply to all hits (which would include pageviews). I want to point out that I have no tested it and that it seems counterintutive, so it might simply be that the documentation is incomplete/wrong here.
However as you are using "classical" Analytics this does not apply to you. Since upgrading the code is a good idea in any case you might want to push for an update to Universal Analytics (this piqued my curiosity so I will test this over the next few days and update this answer with the results - maybe you want to wait until then, or simply test it yourself).
It's possible, but not 100% clear to me that disabling the PageView event on the iframe will prevent your users from registering a page exit (the pageview may get recorded regardless). You can try removing that event and see if it works.
But a better way may be to implement a custom filter on a new View excluding traffic to that specific class of iframes. Make sure you keep your old View (or create a new one with further filters) to make sure you're capturing those iframe views, if you think that's necessary.

Cross-Platform Browser Communication Between Page and IFRAME (Same Domain)

For a specialized purpose with Aweber regarding a newsletter subscription, I have a page loading a nested IFRAME inside, and both reside on the same domain. (Many other stackoverflow posts talk about different domains, but this question deals only with the same domain.) I need a cross-platform way (including browsers as old as the dawn of IE6) for the two to communicate.
For example, someone fills out name and email and clicks a checkbox, and the hidden IFRAME next to the checkbox sits in a setInterval() loop watching for that. When it receives notification, it grabs the name and email and does a form post.
I thought at first that I could just drop a cookie in the parent page, and then the IFRAME child could then sit in an interval watching for that cookie. But my tests show that this won't work. The cookie gets created -- but the IFRAME can't see it. So, I tried the meta-refresh technique in the IFRAME, and again it couldn't see that cookie for some reason.
The only solution I can come up with is that the parent page will take the checkbox click (we use jQuery) and do an AJAX data push to the server into a database. The IFRAME can then check on an interval back to the server via AJAX to see if the database value has changed, and react to it if so. But this seems like an over-engineered solution and I'm looking for an easier alternative that works cross-platform, even in earlier browsers from the timeframe of IE6 and forward.
It's much more simple: In the iframe, you can access the parent variable, which contains the parent window. So you can use parent.document to find the form, read the values, etc.

Resources