I'm working on some wordpress sites, using the Divi theme. I have added this code in the head (Divi -> integration):
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<GA_TRACKING_ID>', { 'anonymize_ip': true });
I have replaced '<GA_TRACKING_ID>' with the right id.
When I inspect it to see if it works, I can't find aip=1. It only says "ep.anonymize_ip: true" at the end of the Request Url and the Query String Parameter inside the collect...>.
Does this make the IP anonymous?
if you use Google Analytics 4, or the one with the code in this pattern G-XXXXXXX (instead of UA-XXXXXXX-XX), you don't have to specify the anonymize_ip since it is already active by default.
Related
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
I am very new in Google Analytics. I am stuck in very basic problem. Actually I have a page abc.com/ab.html . In this page there is a link of xyz.com/getref.html. on getref.html i have paste following tracking code.
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-FAKEID123"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-FAKEID123');
</script>
After clicking on the link on abc.com/ab.html it redirect me on xyz.com/getref.html . But I am not able to get the referrer information in Acquistion/All Trafic/Referrals section. It showing nothing in this section. Please Help me what could be the issue.
We are trying to use Google Signals (https://support.google.com/analytics/answer/7532985?hl=en) for remarketing purposes but we are unsure if it is correctly enabled. We are using the following code for our implementation:
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
if (!cookieManager.googleRemarketing) {
gtag('set', 'allow_google_signals', false);
}
gtag('js', new Date());
gtag('config', 'XXX', {
'anonymize_ip': true,
'optimize_id': 'XXX'
});
</script>
We are not using any additional google ads/remarketing code, but we have enabled "Tracking-Information" => "Data collection" => "Data collection for Google Signals" (the translations might vary, because we don't use analytics in English) in Google Analytics.
It seems like there is no cookie with the name "IDE" set, like it was before when we used the normal Google Remarketing Code. Did that cookie got removed/replaced in google signals?
If so, how can we check if google signals is working correctly?
The Tag Assistant Plugin for Chrome just shows the following:
Thank you!
In your snippet you have:
gtag('set', 'allow_google_signals', false );
so it disable all advertising features.
https://developers.google.com/analytics/devguides/collection/gtagjs/display-features
For this reason you can't see any IDE cookie.
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');
I've set up a new Analystics account, and copied over the tracking code. It's of the kind
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-X');
</script>
I then track an event using
gtag('event', 'click', {
event_category: 'acquisition',
event_action: 'click',
event_label: 'download',
event_value: 1
});
I've tried all kinds of gtag() syntax, however nothing ever gets sent to Analytics. When checking the Network tab in Chrome debug tools, there is no communication with Google at all. (the dataLayer array is properly populated)
I don't want to use Google Tag Manager, just looking for a simple "track event via Javascript".
Looks like it is working, might be a local computer/browser addon that's blocking the call to GA