Getting started
- First of all, install and activate the GDPR Cookie Consent plugin.
- From your WordPress dashboard, go to the GDPR Cookie Consent.
Pre-requisite
As a first step, please remove the Google Analytics/ Google tag manager script that are already installed on the site via the site theme header.php file (common method) or via some other plugin like GA Google Analytics or Google Tag Manager for WordPress.
That is, if the script is added via theme, please remove it or if the tracking is implemented via a plugin, please disable that plugin. Then, follow the below steps:
‘Google Analytics’ implementation
- Login to Google Analytics dashboard.
- Click on the Admin link in the left panel.
- Open the Tracking Info link from the Property view and then click the Tracking code.

Copy the entire script from the Website Tracking section to the clipboard.
Sample code:
Sample:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXX-X');
</script>
Then, from your WordPress site admin dashboard:
- Go to GDPR Cookie Consent > Cookie Category view.
- Click on the edit link on whichever category that you need to use to control the Google Analytics tracking. Eg, you can choose Analytics.
- In the category edit page, you will see 2 fields to insert scripts. Paste the script that you copied earlier to either head or body script field based on your preference. In this case of the Google analytics script, you may paste it inside the Head Script field.
You are good to go now. From now onwards the Google Analytics tracking will run only if the visitor enables or accepts the Analytics category.
‘Google Tag Manager’ implementation
- Login to Google Tag Manager dashboard.
- Click on the container(website) that you want to set up.
- Head over to the Admin tab from the top bar > Click on Install Google Tag Manager.

Now, in order to add the scripts to the website:
- Open the WordPress site admin dashboard, go to GDPR Cookie Consent > Cookie Category view.
- Click on the edit link on whichever category that you need to use to control the Google Analytics tracking. Eg, you can choose Analytics.
- You will see a Head Script and Body Script field in the edit page. Copy the scripts from the Install Google Tag Manager screen into the corresponding fields on the category edit page.
That’s it. From now onwards the Google Analytics tracking will run only if the visitor enables or accepts the Analytics category.
- Was this article helpful?
- Yes, thanks!Not really