0
votes

I set up a Google Analytics tag for my website, and I'm trying to fire custom events, but it's not working. The event is fired from an IFRAME, and it's not capturing in google analytics. If I'm using the full code as below, it works, but I want to split it and use the GA Tag for all websites and set hardcoded custom events within Iframe as the print screen.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-9999999-1"></script>
<script>
 window.dataLayer = window.dataLayer || [];
 function gtag(){dataLayer.push(arguments);}
 gtag('js', new Date());
 gtag('config', 'UA-99999999-1');
</script>
<script>gtag('event', 'visit', {
 'event_category': 'thisweek',
 'event_label': 'today',
 'value': 0
});</script>

So how to fire this event from inside an iframe: gtag('event'.......)

<script>gtag('event', 'visit', {
 'event_category': 'thisweek',
 'event_label': 'today',
 'value': 0
});</script>

How the events fired in the website

1
Your screenshot seems to suggest that Universal analytics.js is possibly being used within the iframeBronwyn V

1 Answers

-1
votes

you need to use full gtag snippet within your Iframe, like:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-9999999-1"></script>
<script>
 window.dataLayer = window.dataLayer || [];
 function gtag(){dataLayer.push(arguments);}
 gtag('js', new Date());
 gtag('config', 'UA-99999999-1',, {'send_page_view': false}); // to avoid unnecessary pageviews
 gtag('event', 'visit', {
   'event_category': 'iframe event',
   'event_label': 'some label',
   'value': 0 
 })
</script>