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>