gtag subdomains in iframe

Viewed 594

I'm trying to handle gtag.js in order to track page views,

It's working fine on standalone pages or in iframe inside the same parent domain but it doesn't work when the iframe parent is not on the same domain (working on firefox but not in chrome/chromium)

  • parent page : abc.domain.com

    • iframe1: def.domain.com
      • gtag page view ok
    • iframe2: ghi.domain.com
      • gtag page view ok
  • parent page: abc.running.com

    • iframe1: def.domain.com
      • gtag page view not working
    • iframe2: ghi.domain.com
      • gtag page view not working

I control domain.com, i don't control running.com, my iframe is just included in it with an external script

gtag page view ok = i can see the collect http request in network inspector

gtag page view not working = i cannot see the collect http request in network inspector on chrome/chromium but i'm able to see in on firefox

My gtag javascript code included in the iframe is pretty simple:

<script async src="https://www.googletagmanager.com/gtag/js?id=TAGID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'TAGID', {
     page_path: "/page1",
     page_title: "Page 1"
  });
</script>

I tried to add the cookie_flags fields but it's not changing anything

<script async src="https://www.googletagmanager.com/gtag/js?id=TAGID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'TAGID', {
     page_path: "/page1",
     page_title: "Page 1",
     cookie_flags: "samesite=none;domain=domain.com;secure",
  });
</script>
1 Answers

I assume that your page and Iframe are both accessed via HTTPS and have a valid SSL certificate? This is important for the SameSite/Secure flag.

I believe there is no cookie_flag domain and it is not necessary to set the domain.

The following should be enough

 cookie_flags: "SameSite=None;Secure",

If it is not working, please check (or add a screenshot) of the cookies in chrome dev tools in the scope of the Iframe (Application -> Cookies -> def.domain.com)

Related