Refusing Google Analytics cookies for GDPR with Wordpress - wordpress

This is a new problem I never faced before.
I have a website made with Wordpress. In this site I want to include Google Analytics, so I added the following snippet into my <head>. (With the proper UA, of course)
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
</script>
Now, when the page loads, the following cookies are set automatically: _ga, _gat_gtag_UA_XXXXXXXXX_X and _gid
Now, I need to show the users an option to either accept or refuse cookies when visiting my site. For that I choose Cookiebot, to see this dialog.
But when the site opens, before the user had any chance to click either button, the cookies are already set.
Why is this? Am I misunderstanding anything about how cookies/GDPR work?

Related

Issue with GA4 tag setup and ads conversions

I am having an issue with Google Ads where none of my ads are showing conversions. When I contacted Google support, they told me that my GA4 tag was set up incorrectly and this was the issue however I copied the tag from the admin of my google account. The only error I can see is this one that shows up in tag assistant:
This is the code that I have installed on my website:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
I don't understand what the issue is, I copied it straight from the analytics admin. I asked support but they said they weren't trained in this area so couldn't help. Does anyone know why the tag is wrong and what I am missing that will enable me to see conversions in Google Ads?

Google tag assistant reports: “Same web property ID is tracked twice”when trying to install google analytics code

I was trying to install google analytics code into our google tag manager at first I installed the GTM and add a tag that I grabbed from tracking ID and after all that, it doesn't seem to appear an analytical dashboard on my account.
I was wondering how do I fix this error on Google tag assistant and also to have the dashboard appear. thank you so much.
page script
script below
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-171638252-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-171638252-1');
</script>
Errors shown as below image,
This double-tracked ID's behaviour could be caused if you have loaded your tracking code both inline on the website, and through GTM as well. Please make sure that you do not load your tracking both inline on the website, and through GTM. This is my initial guess so far, unfortunately, I could not give you a final solution to this issue without seeing the source code and domain.

Google Analytics Web+App event config: Error 'gtag is not defined'

I'm trying to setup ecommerce event configuration of Google Analytics App+Web for a website. Refer to the documentation here.
Because there is a lot of custom code for the ecommerce configuration, I cannot use the general GA App+Web webevent template, so instead I'm using a custom HTML-tag in this case.
As a first test, I tried to fire the following simple event:
<script>
gtag('event', 'blabla', {
'test_param1': 'test_value_1'
});
</script>
However, the event is not correctly sent to GA; instead, the following error in the console is returned:
Uncaught ReferenceError: gtag is not defined
To reproduce, see the following page: https://www.hema.nl/mooi-gezond/make-up/make-up-accessoires/toilettassen-1/toilettas-11830901.html
Additional information:
The GA App+Web base initialization is (successfully) done via GTM, via the GA App+Webconfiguration template tag.
I also configured a few other (simple non-ecommerce) GA App+Web events via GTM via the GA App+Web webevent template tag , and these events are sent to GA successfully.
Does anyone know what's going wrong, why the console error appears and why the event is not sent to GA?
Short answer
Additionally to the GTM GA App+Web tag, you need to add the following code to have gtag() defined:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
</script>
Long answer
According to the official documentation (https://developers.google.com/analytics/devguides/collection/ga4) this is the code you should include in your site:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'MEASUREMENT_ID');
</script>
After inspecting a website with this tag I found GTM has injected that first line, which is enough to make analytics work. But it didn't add the other lines, some of which effectively defines the gtag global function as a "syntax sugar" for pushing things to the Analytics Data Layer.
Personally, I find this really strange, since using GTM is the most cannonical of adding Google Analytics to a website and it's by the same company.
The cause of the problem has been found. The problem seemed to be that gtag() does not work if the App+Web base setup is done with the GTM App+Web base template tag. Instead, an event should first be pushed to the GTM datalayer, and then the GTM App+Web event template should be used to send the event to Google Analytics.
Lots of thanks Gino (working at Merkle) for fixing the issue!
In my case Uncaught ReferenceError: gtag is not defined was caused by uBlock/adblock turned on.
I think it's worth testing if accepted answer doesn't work.
2022 Year answer:
For anyone struggling with using GA4 gtag and GTM (Google Tag Manager) simultaniously in your SPA/Angular/React app, you should do next:
don't use built-in GTM's "Google Analytics: GA4 Configuration" tag configuration
do use "Custom HTML" GTM tag with exactly that gtag JS code from your Google Analytics, i.e.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>
After that you can use gtag in your code as you intended to do, all should work. No whole Firebase needed or something. Possibly you will need to have
gtag('config', 'GA_MEASUREMENT_ID', {
send_page_view: false
});
to disable automatic page_view tracking.
If you're using Google Tag Manager, the gtag function doesn't exist. Follow this guide to create custom events
Basically the code you use is
dataLayer.push({event: 'event_name'});
Then you setup a tag in GTM for GA4 event. Use the event name that you want to see in Google analytics. For the trigger, use custom event. Here, in the event name, use the name that you used in your code event_name
I found out that it was due to an AD Blocking Extensions added to my chrome
This may be a bit of a repeat of the accepted answer, but I wanted to confirm that it is indeed recommended by (some) Google documentation to manually add the following snippet of code to the <head> section of your website, just above your existing Tag Manager container snippet:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
</script>
This is necessary if:
You are deploying your Analytics Tags using Google Tag Manager rather than the "Google Tag"
You wish to utilize the gtag() syntax to send Events to your GA4 Analytics property
Source: https://developers.google.com/analytics/devguides/migration/ecommerce/gtm-ga4-to-ua#4_enable_the_gtagjs_api

using global site tag (ga gtag) code for custom tags

Can this one gtag code from GA be used for own tags, or does tag manager need another tag on each page?
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=xxxx"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', xxx');
</script>
As per Google Analytics documentation:
To install the global site tag, copy the following code and paste it immediately after the tag on every page of your site. Replace GA_MEASUREMENT_ID with the ID of the Google Analytics property to which you want to send data. You need only one global snippet per page.
https://developers.google.com/analytics/devguides/collection/gtagjs#install_the_global_site_tag

Google Analytics and Sharepoint Online

I would like to know how and where to add this code to SharePoint and start tracking usage via Google Analytics. I've seen conflicting information about adding to the master page and . When I reupload to Master Pages and Page Layouts the changes are not shown. Can anyone help please?
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxx"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxx);
</script>
If you are using the classic pages, you should be able to add your script to the head tag of your masterpage and publish.
If you're using the modern pages, you might be able to use the SPfx extensions.

Resources