Google analytics not recording content_group - google-analytics

I had the current code in my WebSite, and it was working until a week ago:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-142497713-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXX-1');
gtag('set', {'content_group1': 'Guests'});
</script>
When my User log into my site the 'content_group1' becames 'My_User_type'.
I used to have charts filtered by content_group1 to see the typology of my users and how much they use my website.
Now it's not saving data of content_group1 and i cannot understand why. (I didn't change the footer of my page!)
Anyone have the same issue?
Thanks.
Dario.

You need to call the "set" before the "config". Also using content groups like this is messy, the intent for this dimension is to group the content (ie, support, product), not for what the user type is. You should look into setting a custom dimension OR use the userid feature for your use case.
gtag('set', {'content_group1': 'Guests'});
gtag('config', 'UA-XXXXXXX-1');

Related

What's the correct way to include both GTM and gtag scripts?

I'm using both gtag as well as GTM; how do I correctly include both of them in the ? Also, I was wondering if I should be overriding the dataLayer variable or checking if it already exists on every page -- i.e. dataLayer = []; or window.dataLayer = window.dataLayer || [];?
Does this look correct?
<!-- Google Tag Manager -->
<script>
window.dataLayer = window.dataLayer || [];
</script>
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
<!-- End Google Tag Manager -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UAXXXX"></script>
<script>
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXX');
</script>
This fully answers your concern: https://support.google.com/tagmanager/answer/7582054?hl=en
In short: remove your gtag completely and have all your tracking logic within GTM.
A tag manager is meant to house all your analytics logic and be the single point of access to anything behavioral tracking-related.
Regarding your DL question,
window.dataLayer = window.dataLayer || [];
is more adequate. Never redefine/overwrite the DL. Even when you believe it's not there. Async can be vicious, so be safe is always good in this case.
Oh, also GTM provides dataLayer automatically, so if you're moving your logic to it, you can as well skip defining it to leave the source cleaner. Or you can define it on the template level in case you want to be able to push into it before GTM is loaded.

Prevent gtag / global site tag from tracking initial page load

We have a single page application using Gtag (Global Site Tag), and we manage the tracking of pages manually to provide the correct page names that we want to track. So we call
gtag('config', gaPropertyId, gtagPageConfig)
every time there is a route change.
This means that we don't want gtag to track pages for us automatically, as we are currently tracking all initial pages twice. The first is when gtag is automatically firing the tracking of the page by sending the browser title and the URL, and the second time is when we trigger the page view from our code, to provide the title for that page that we want to have see in Google Analytics.
After a lot of research and debugging, I've narrowed it down to the settings screen, where "Page loads" is checked, and can't be disabled, see this image:
We load our script like this:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxx-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-xxx', { 'send_page_view': false });
</script>
When I remove the line gtag('js', new Date());, it doesn't track the page anymore, but this will probably result in some unwanted behaviour.
Is there a way for us to prevent the initial page load tracking? I've searched everywhere, but can't find the solution.
Simply you should NOT include those fields on pages you don't want to send any data to Google:
gtag('js', new Date());
gtag('config', 'G-xxx');
Your snippet should look like this without date and config:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-xxx"></script>
<script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}
Sending data
SPA (i.e. Vue, React, etc)
If you are using SPA (i.e. Vue, React), you can run gtag function after route updated:
gtag('js', new Date());
gtag('config', 'G-xxx', { page: path: route.path, page_title: route.meta.title })
PHP
You can show up date and config conditionally:
<?php if (/* suits my needs*/): ?>
gtag('js', new Date());
gtag('config', 'G-xxx');
<?php endif; ?>
Documentation says about measure pageviews:
To disable the default pageview hit, set the send_page_view parameter to false in the gtag.js snippet.
gtag('config', 'GA_MEASUREMENT_ID', {
send_page_view: false
});
https://developers.google.com/analytics/devguides/collection/gtagjs/pages

Google Analytics gtag doesn't count

I am using gtag and event tracking. However, it doesn't count at all... I have no idea why it doesn't work even though I clicked the link. Always it shows 0. Please give me any advice. Thanks.
<script async src="https://www.googletagmanager.com/gtag/js?id=my id"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'my id');
</script>
test link
I am using the following construction:
Link
it works for me:
P.s. I didn't configure anything on GTM and GA.

How to implement the Google Analytics event monitoring on a website if the standard Analytics tracking code seems not to be enough?

The website www.3dz.it is using with WordPress.
There are four languages and each one on a different domain (Italian .it, France .fr, etc.). It is in this way using WPML with the multi-domain option, since April 2018.
Up to April 2018, the events monitoring was going. For three months with the four domains, we were without data; in July we add the new analytics code so each language has an own Analytics property.
But we are still without the monitoring of the events.
Google analytics tracking code is since July 2018 set how is actually online.
<?php if(ICL_LANGUAGE_CODE=='en'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-4');
</script>
<?php } elseif(ICL_LANGUAGE_CODE=='it'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-1');
</script>
<?php } elseif(ICL_LANGUAGE_CODE=='es'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-3');
</script>
<?php } elseif(ICL_LANGUAGE_CODE=='fr'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-5');
</script>
<?php } ?>
Someone can tell me please how to implement the code to obtain the monitoring of the events again?
Maybe you could try to add the tracking codes on the website using Google Tag Manager? It's very easy to add multiple tracking codes into your Google Tag Manager account and only place one GTM-code to your website.
The developer notes are pretty straightforward with regarding adding event tracking to the page, for the gtag version of GA. However, I would also agree that managing your GA set-up and event tracking via Google Tag Manager would be more appropriate and scalable for your situation.
The problem was the different library of Analytics. I solved it calling google assistance. I changed the event script in the website and I modified the conversion in Analytics (event categories and actions)

Google Analytics gtag.js Iframe Cross-domain Clientid issue

Our goal here is to keep Google Analytics conversion goal tracking data when we load an iframe from another domain name that we own.
We have a domain rentalbookingsoftware.com that on the free trial page: https://rentalbookingsoftware.com/free-trial-signup/ loads an iframe for our free trial installer from sidev2.info like this:
<iframe width="80%" height="500" src="https://sidev2.info/freetrialform.php"></iframe>
We are trying to keep the gtag.js clientid the same but a new session is started on the sidev2.info gtag tracking which causes the correct referrer information to be lost as you can see from the gtag recording: https://www.screencast.com/t/l5wsqUF6oAg . Both sites are using this tracking code as suggested from: https://developers.google.com/analytics/devguides/collection/gtagjs/cross-domain and I have added sidev2.info to the referrer exclusion list: https://support.google.com/analytics/answer/2795830
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-45446232-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-45446232-1', {
'linker': {
'domains': ['rentalbookingsoftware.com', 'sidev2.info']
}
});
</script>
How can we keep the clientid using gtags? I found this: https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain but it is for analytics.js tracking, should we switch to that tracking method?

Resources