Reputation: 111
I have google analytics running on my website: mydomain.com Another website (anotherdoamin.com) that I don't own has embedded my website in an iframe on one if its pages.
I want my websites analytics to work in the iframe in anotherdomain.com . can any on help me with that?
Upvotes: 5
Views: 3013
Reputation: 656
If I understand correctly,
If you are using the default/standard Google Analytics templates, its cookies only work in first-party context. They are subject to SameSite attribute. You embedded site won't be able to access the GA cookie(s) and GA won't send any events then.
This can be fixed.
ga('create', 'UA-XXXXXXXX-YY', {
cookieFlags: 'samesite=none;secure'
});
gtag('config', 'UA-XXXXXXXX-YY', {
'cookie_flags': 'samesite=none;secure'
});
gtag('config', 'G-XXXXXXXX', {
'cookie_flags': 'samesite=none;secure'
});
Other option could be that example.org embeddeds your example.com as a sandboxed iframe, e.g.
<iframe src="https://example.com/" sandbox></iframe>
which will prevent your site from loading and executing GA.
Apart from the iframe's sandbox attribute the iframe might be also subject to "Content Security Policy (CSP)" or "Permissions-Policy"
You should check example.org's source code to learn more about how your site has been embedded and probably want to contact example.com to change it.
Either way, in GA all your events will appear as being sent from example.com. Without additional efforts, you won't know that the events originated from example.com embedded in example.org.
Upvotes: 10