Embed Google Analytics in WordPress [2021]
Marc Wagner
June 29, 2021
Google Analytics collects information from your visitors. This data can help you improve the user experience. In addition to visit numbers, length of stay and page views, you can also query demographic data of your visitors.
Don’t feel like reading? Then just watch our video tutorial:
Google Analytics mit Cookie Opt-in #
With the introduction of the GDPR in May 2018, the guidelines for cookies were also redefined. When cookies are set, the visitor must first be asked whether they want to allow this. For this reason, Google Analytics may no longer be integrated directly into the page.
The remedy is the WordPress premium plugin Borlabs Cookie.
Install the plugin to start integrating Google Analytics into WordPress. After the installation, go directly to Borlab’s Cookies and enter your license first. After that, all settings options are available to you.
To integrate Google Analytics, you now have to switch to the Cookies tab. Then scroll down to the Marketing item and click on the Add new button.
After that, you just need to choose the appropriate service. This is already supplied by Borlabs Cookies as a template.
The template already contains all information about the provider, the cookies and the runtime. All you have to do now is enter your tracking ID in the additional settings.
Afterwards you save the whole thing and the integration is already finished.
Now you just need to change the status of Borlab’s cookie to show the pop-up. You can find the option for this in the Settings tab.
It is advantageous that Borlabs Cookie is already delivered with standard texts. Further adjustments are therefore optional for the time being.
As soon as you reopen your page, the pop-up will appear. The Google Analytics script we added above will be loaded only after confirmation.
Disable old Google Analytics integrations #
After you have integrated Google Analytics with Borlabs Cookie into WordPress, you should definitely remember to remove old integrations.
The best way to do this is to first check the WordPress Plugin Manager to see if you have installed another plugin for statistics, such as Google Analytics. Normally it is enough to deactivate the plugin to remove the script.
In some cases, the script may also have been integrated directly into your theme. Therefore, you should check your theme options as well.
Another method was to integrate the script directly into the WordPress header. Therefore, you should also check whether Google Analytics was possibly deposited there.
Check if Google Analytics was loaded without opt-in #
Thanks to Google Chrome’s development console, you can find out in no time if Google Analytics is loading without consent.
Don’t feel like reading? Then take a look at our video tutorial:
The best way to do this is to switch to Chrome’s incognito mode. You can open this mode with the key combination Ctrl+Shift+N.
After that, simply open your website. If you did everything correctly, you should now see the cookie opt-in pop-up from Borlabs.
Ignore the pop-up and open the development console of your browser with the F12 key.
Then switch to the Application tab.
On the left side, you will find an entry named Cookies under Storage. Expand this entry by clicking on the arrow. There you should see the domain of your website. Click on it.
On the right side, you will now find a list of all cookies set by your website.
Ideally, this list is empty.
However, if you see entries like these, some plugin, theme or manually added code is unintentionally loading Google Analytics. Therefore, you should start searching to find out which script is responsible for this.
Google Analytics and privacy #
Since the introduction of the GDPR, some precautions have to be taken to be able to use Google Analytics on your site:
- Conclude order processing agreement with Google:
You can do this quickly and easily via your Google Analytics account. You can find instructions in the Google Analytics Help. - Anonymize IP:
Next, you should enable IP address anonymization. To do this, you just need to add the following to the script:
gtag(“config”, “%%trackingId%%”, { “anonymize_ip”: true });
If you are using Borlab’s cookie, this line should already be there. To be on the safe side, you should still check it. - Do not use “User ID function”:
Unfortunately, this feature is not privacy compliant. You should therefore not use it. - Opt-out Cookie integrieren:
In addition to the opt-in, you must of course also offer your visitors to manually deactivate the collection of data. You can read how this works in Google’s user opt-out article. - Limit retention of user and event data:
Google Analytics offers you the possibility to determine the duration of the data storage yourself. You can find this in your settings under Tracking information / Data retention. The storage period should not be longer than 12–14 months. Also disable the Reset on new activity option. - Customize privacy policy:
Don’t forget to also fully inform your visitors in the privacy policy if and how you use Google Analytics. Here you should also refer to the opt-out.
Artikel von:
Marc Wagner
Hi Marc here. I’m the founder of Forge12 Interactive and have been passionate about building websites, online stores, applications and SaaS solutions for businesses for over 20 years. Before founding the company, I already worked in publicly listed companies and acquired all kinds of knowledge. Now I want to pass this knowledge on to my customers.