+5 votes
in Blogs by (242k points)
Integrate Google Analytics in WordPress: possibilities and privacy measures

1 Answer

+3 votes
by (1.6m points)
Best answer

Google Analytics and WordPress: three possibilities
Google Analytics and data protection
Google Analytics plugin for WordPress
Google Analytics tracking code
Google Tag Manager for WordPress


Integrate Google Analytics in WordPress: possibilities and privacy measures

Google Analytics collects various information about visitors to your website. For example, this tool displays information about who visits the web, how often and for how long , demographics, and what end devices are used by site visitors..

This information can be useful in many areas. For example, with it you can personalize or create content marketing strategies by analyzing the most popular articles, pages, products or other content, as well as improve inbound marketing , better target audiences, optimize user experience and increase sales. conversion rates. This is why Google Analytics is the best standard tool to optimize the performance of your WordPress page in the long term.

  1. Google Analytics and WordPress: three possibilities
    1. Google Analytics plugin for WordPress
    2. Google Analytics tracking code
    3. Google Tag Manager for WordPress
  2. Google Analytics and data protection

Google Analytics and WordPress: three possibilities

Before integrating Google Analytics into WordPress, create a new Google Analytics account by clicking the button? Get started for free? on the main page of the Google Marketing Platform. After creating the account, you will find the tracking code created by Google for your website in the tracking section of the website. You can embed this code in WordPress later..

First of all, you need a free Google Analytics account and the corresponding tracking code.

In this tutorial, we tell you how to use the tracking code to integrate Google Analytics in WordPress and what you should keep in mind in relation to data protection.

Google Analytics plugin for WordPress

The easiest way to add Google Analytics to your website is with a plugin , since this way it is not necessary to edit the page code . There are several WordPress plugins available, which make it easy to integrate Google Analytics into WordPress. We recommend Jeff Starr's free GA Google Analytics plugin , with over 400,000 active installs and an average rating of 5 stars..


IONOS WordPress hosting is very simple: it offers a number of perfectly configured extensions to make your work easier, so you can start creating content on your new WordPress page right away.

After installing and activating the plugin , you must embed the Google Analytics tracking code obtained previously in the settings. Open the Google Analytics tab in your WordPress control panel, in? Settings ?. In the plugin settings , insert the tracking ID in the appropriate field . After inserting the code, scroll down and click the "Save changes" button. Google Analytics should now be active on your WordPress website.

In the plugin configuration, you have to enter the tracking ID to use Google Analytics in WordPress

Google Analytics tracking code

If you don't want to use a plugin , you can embed the Google Analytics tracking code directly into the WordPress theme via the functions.php file . To manually enter the Google Analytics tracking code, it is important to use a child theme. This will prevent the tracking code from being overwritten with every WordPress theme update.


A WordPress child theme is a theme that inherits the functions of another main theme or template, called a parent theme (or mother theme).

To add the code to the WordPress website, go to the theme editor and find the header.php file. There the Google Analytics tracking code is inserted directly before the closing </head> tag in the editor .

Paste the tracking code that you get in your Google Analytics account in header.php

Click on the button? Update file ?. Google Analytics tracking code has been added to WordPress.

Google Tag Manager for WordPress

Furthermore, there is the possibility to integrate Google Analytics into WordPress with the help of the Google Tag Manager.

Google Tag Manager is a tag management system that allows you to manage your website's tags and code instead of editing the code directly in WordPress . This reduces the risk and possibility of errors and allows editing without the need for development skills . To simplify installation, you can use Google Tag Manager as a WordPress plugin .

Download the plugin , install it and activate it . Create a Google Tag Manager account and a new container . Copy the container ID from the Google Tag Manager control panel by opening the? Administration? and looking for a string of characters beginning with? GTM ?. On the WordPress website , paste the Google Tag Manager ID into the corresponding field on the plugin's settings page , under? Settings ?, on the? Google Tag Manager ?.

The tag configured in Google Tag Manager now works on the WordPress website through the plugin .

Google Analytics and data protection

According to the latest ECJ rulings, Google Analytics can no longer be used without the consent of visitors. Therefore, you should take some precautions to ensure the use of Google Analytics on your website while respecting privacy :

  1. Accept the new Google data processing conditions:
    You can accept the data processing conditions directly in your Google Analytics account. To learn more about the contract, see the Google support page.
  2. Activate IP anonymization:
    Adapt the tracking code with the function? _Anonymizelp? in the JavaScript library? ga.js? to ensure that the IP address of your visitors is not saved in its entirety . The last digits, which allow the computer used to be identified, are replaced by the digit 0. You will find more information about IP anonymization on the Google support page.
  3. Give up the user identification function:
    The new version of Google? Universal Analytics? processes even more data than the standard version. Therefore, in this section the user identification must be disabled or not used. Cross-device tracking, which allows the website operator to track user identification even more effectively, can cause privacy concerns.
  4. Deactivate the target group function (the so-called remarketing ):
    This setting can be configured in the properties options in Google Analytics . You will find more information on the Google support page.
  5. Implement the deactivation extension:
    The visitor has the option to refuse the collection of usage data (the so-called opt-out) . This can be done in all common browsers, but not on mobile devices.
  6. Implement the opt-out cookie :
    With a simple click, the visitor can stop the analytical tracking and thus also reject it. You can find instructions to implement it with JavaScript ( disabling tracking ) in this Google article.
  7. Limit the storage period:
    Limit the data storage period in the settings (max. 14 months) and deactivate the? Reset on new activity ?.
  8. Inform in the privacy policy:
    You must inform your visitors about whether you use Google Analytics and how you do it in your privacy policy . You should also list the points mentioned above: data processing, IP anonymization and rejection options ( browser plugin and opt-out cookie).

There are other tools to analyze the performance of your website. Some alternatives to Google Analytics give more importance, for example, to data protection.