We have a page used for ads that feature an iframe of a form (all on the same domain). The page and the iframe are both being tracked in analytics, but we only want the main page to be tracked. Our analytics are not accurate due to this and I am trying to turn off tracking for the iframe page. I just want the parent page to be tracked and not the page that is in an iframe on the parent page.
Have tried setting up a filter on GA but that had the opposite effect we needed.
A possible solution would be to check if the current page sits in an iframe and, if so, use an exception trigger on your Google Analytics tags.
E.g. you could create a custom javascript variable "isIframe":
function() {
return window.location !== window.parent.location;
}
If this returns true, you are inside the iframe.
Then you create trigger of the "custom event" type, enable regex matching and put in ".*" in the event name (so this catches all events). Select "fires on some events" and set "isIframe equals true" as condition. Attach this as an exception trigger to your GA tracking tag(s).
Now if your GTM instance runs inside the iframe the tracking is blocked (so the iframe will not be counted as a pageview), but the tracking for the host page will still work.
Related
I want to attribute the purchase event and other events made inside an iframe to the source from where the user came from (Ads/UTM) on the parent page.
According to Google (Link below: Manual setup Method), if I initialize Google Analytics 4 (ga4) inside the iframe with the same client_id and session_id as the parent page, it will be considered the same user.
However, when I try this, a new user and session are being created even though the cookie values for _ga and ga are the same for both the parent and the iframe. I have confirmed that these cookie values are the same.
https://support.google.com/analytics/answer/10071811?hl=en#zippy=%2Cmanual-setup
Is there something I am missing or doing wrong?
I have a form that when submitted it goes to a different "success page" and I want to use that landing page to track conversions or count how many times people hit the "submit". I could use a page view tag but then that will fire every time someone goes to that page. So perhaps if someone hits the back button and reloads the page then that will count as a form submit.
So I would like to make a page view Tag in google tag manager that only fires if the page view is coming from a specific URL or referred from a specific URL. Is this possible?
Thanks in advance.
It is possible. Enable the built-in "referrer" variable, and on your target page create a trigger "pageview", with an added condition "referrer equals <your referrer>".
Some browsers might not send a referrer header, so this is not 100% reliable. If the page that sends the traffic is under your control, you might consider using a tracking parameter instead.
I need to add a LinkedIn pixel to GTM to track Drift chat widget being clicked.
I have already added the LinkedIn pixel to a GTM tag, I know I did that correct. I created a GTM trigger that is set with the GTM tag and I'm having problems with the GTM tag not triggering. I have tried:
Trigger Configuration -> Trigger Type -> Click - All Elements
This trigger fires on -> Some Clicks -> Fire this trigger when an Event occurs and all of these conditions are true -> Click Classes -> equals -> [some class names I see when inspecting element]
The widget is placed inside an iframe. Should I assume any attempts to capture clicks from elements in the iframe will fail? When I "Preview" in GTM, view our site with the Tag Manager window open and then click the Drift chatbot widget - the GTM tag I created doesn't fire.
You won't get events from the iframe by default.
the iframe is a separate, complete HTML page. If this is a third party widget, then it sounds like a safe bet that your GTM code is not embedded into that page, so you can catch events via the native GTM functions.
as a third widget this runs most probably not on the same domain as your page. Cross-Domain communications with iframes is not something that happens by default (that's a security feature). If you can place Javascript into your widget, then you can communicate with your main page via window.postMessage (but then if you can place code you might be able to embed your GTM instance).
If Drift has something like tech support I would suggest to contact them - this is such a common issue that it's quite probable that they will have a solution ft it.
When using the Google Tag Manager, is it possible to track some things the old way in addition to using the GTM?
For example, I use GTM in order to fire a page view.
However, I want to fire another page view, when a user clicks a button, also known as a virtual page view.
The button in question doesn't have an ID and I don't trust the othet agency, which handles these buttons to consistently keep the same IDs for these elements. So I would rather have them be responsible for these types of page views.
The code for the virtual page view would look something like that:
ga('send', {
hitType: 'pageview',
page: 'button2'
});
Since the tracker is already initialized by GTM, I would only have this code outside GTM.
Would this work if all other google analytics related things run over gtm and where should I put this code in this case? Somewhere after the GTM code on the page I'd imagine?
Google Tag Manager (GTM) by default uses a random name for each tracker, generated for each Universal Analytics tag. There is a possibility to use fixed name for trackers, which is highly discouraged. This means, that you might have difficulties to identify the proper tracker to use, when sending your additional pageview data.
There are however other methods to send virtual pageviews using GTM, where you can benefit from your existing Analytics settings, defined in Google Tag Manager. (Preferably by using Google Analyitcs Settings variable.)
As far as I understand, you have control over the code, to run some JavaScript on the relevant click event.
So instead of directly invoking the ga object, you can send the desired data to GTM, with a call like this:
dataLayer.push({
event : 'virtualPageView',
virtualPagePath : 'button2'
});
Obviously, there are a couple of things you need to set up in GTM, which will be able to act on this event, and send the pageview to Google Analytics.
Create a variable that points to virtualPagePath dataLayer variable, so the newly pushed value could be reused
Create a custom event trigger, that can be used with one or more tags. The event name should match your given event name, virtualPageView in my example.
You need an Universal Analytics tag, which will send the pageview. This tag should be fired by your new custom event trigger, and should have an extra setting compared to your regular pageview tag. Namely, page variable within the Fields to set block should point to the newly created dataLayer variable, that contains your virtual page path.
This way, Google Tag Manager will take care of creating the tracker for you, sending the hit to Google Analytics, and using the virtual page path variable provided by you, instead of the URL in the browser address bar.
I'm trying to integrate Google Tag Manager with my Ember app. I'm having a hard time understanding how to notify GTM that the page changed, and send a page view event.
I've read a lot of things online, mostly working around creating a new variable for a "virtual page" or something, but obviously this is far from ideal.
I'd like to be able to just use dataLayer.push to notify the page actually changed. Is there an easy way out I didn't find or is it really a pain to track with GTM on SPA?
This was asked quite a while ago. With the current feature set of GTM, you can easily set up SPA page tracking without much trouble.
First, go to Triggers and create a new trigger. Select History Change as the trigger type. This will create a trigger that fires every time the location history changes.
Then create a new Tag of Universal Analytics type and set it up as per the screenshot below.
[
As for the trigger, set the previously defined History Change trigger, and you're done. Every time a navigation occurs in your SPA, a page view event with the proper page path will be triggered.
EDIT: as trognaders pointed out in a comment, this does not track the initial page view. To remedy, simply add an additional trigger for your tag that fires on the Page View event (All Pages). See screenshot below.
You definitely need to push events into the dataLayer which you can then trigger a GA page view tag in GTM. So to push an event into the DL:
dataLayer.push({'event':'virtualPageView'});
Then setup a trigger called 'vpv' which fires on a custom event called 'virtualPageView'. Add that trigger to a GA tag.
The best thing to do is also send through the details of the virtual page when you send the event. This way you can set up variables that pull these dataLayer property values into the page view call. So you might do this:
dataLayer.push({
'event':'virtualPageView',
'page':{
'title':'contact us',
'url':'/contact'
}
});
So you'd setup a variable called 'DL- page title' (for example) which is a dataLayer value of 'page.title' and another variable called 'DL - page url' which is a dataLayer value of 'page.url'.
You then setup a new Universal Analytics tag which has all your usual pageview settings but with 2 'Fields to Set' (under More Settings). Set 'title' to {{DL-page title}} and 'page' to {{DL - page url}}
Finally set the trigger to 'vpv' and you'll find everytime you push the event + data into the datalayer you'll get a pageView fired off with your virtual page's title and virtual url.