Setup cross-domain tracking for iframe - google-analytics

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?

Related

Set up Google Tag Manager tag exceptions based off of user/traffic source

I have a Google Tag Manager event that is currently firing for all pages, and so all users. Is there a way to add a custom exception for this event to trigger depending on where the user has come from (traffic source)?
Yes, it is indeed possible. The problem, however, is that the source information is typically not saved after the first pageview. So you'll have to save it.
First, make a custom HTML tag that would fire on every page, and set their document.referrer in a 30-minute cookie if that cookie doesn't exist.
Now just use that cookie's value via a CJS variable, or just use it directly in your blocker.

Iframe and parent page both being tracked by GA

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.

Execute Google Analytics Functions in addition to Google Tag Manager

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.

Google Tag Manager tag is fired but event does not show up in Google Analytics Real Time Events Tab

I have created a tag which fires when the click url contains certain words. When I view the website in GTM debug mode the tag is getting fired. But the event is not getting captured on Google Analytics Real Time Events.
The following is the screenshot of my tag and trigger.
Will the real time events in Google Analytics not show until I publish the changes in GTM?
What the possible problems you may have(as you are saying your tag is firing and IP was not filtered in GA:
Your tracking ID for GA is incorrect(or you are checking data in the wrong GA property): your tag config looks correct, so data should be sent to GA(as you are saying GTM trigger works fine);
Trigger name is hidden, but looks like trigger type is "Click". Make sense to check if option "Wait for tags" was enabled. If this option is disabled and after click user redirecting on another website page, GTM may not have enough time after click and before redirection to send data to GA. And your tag will fire, but data will not be received to GA.
I had the same problem. It ended up being a double up in the GA id. I had used a constant variable to define the GA property but not removed the ID itself.

Google analytics iframe tracking

I'm looking to track iframe and the content/destination url in the iframe. But the requirement is GA Event tracking generated from iframe inherits the page level dimensions &metrics set by page view and looking to pass same cookie value from parent iframe. Can anyone help on this.

Resources