Google Analytics collects all kinds of data that can tell you about the visitors that come to your website. For example, it groups data on who visits your site and how long they stay, what the demo­graph­ics of your visitors are and what devices they use.

The in­form­a­tion collected can be useful for many different purposes. Content Marketing Strategies can be set up or adjusted based on the most popular posts, pages, products or other content, and it allows for better inbound marketing with a clearer idea of the target audience in order to optimise user ex­per­i­ences and increase your con­ver­sion rate. Google Analytics is the best standard tool to con­sist­ently optimise the per­form­ance of your WordPress site.

Google Analytics & WordPress: three different tech­niques

Before adding Google Analytics to WordPress, you first have to go to Google marketing platform and click on “Start for free” to set up a new Google Analytics account. Once you do this, Google will give you a tracking code for your website under Admin Tracking in­form­a­tion. You can add this code to WordPress later.

In this section, we’ll show you how you can use the tracking code to add Google Analytics to your WordPress website and what you need to pay attention to in terms of data pro­tec­tion.

Google Analytics plug-in for WordPress

The easiest way to add Google Analytics to your website is by using a plug-in. If you do this, you don’t need to change the code of your site. You can choose from several WordPress plug-ins to add Google Analytics to WordPress. We recommend the free GA Google Analytics plug-in from Jeff Starr, which has over 400,000 active in­stall­a­tions and an overall 5-star rating.

Tip

IONOS Hosting for WordPress sim­pli­fies things – with a range of perfectly matched ex­ten­sions to make your work easier, you can start putting content on your new WordPress site straight away.

Once you install and activate the plug-in, you need to enter the Google Analytics tracking code into the settings. Open the Google Analytics tab from your WordPress dashboard. In the plug-in settings, add the tracking ID to the relevant field. Once you’ve entered the code, scroll to the bottom and click “Save changes”. Google Analytics should now be active on your WordPress site.

Google Analytics tracking code

If you don’t want to use a plug-in, you can add the Google Analytics tracking code directly to your WordPress theme using the functions.php file. Here’s how.

When you’re manually adding a Google Analytics tracking code, it's important to make sure you use a child theme. This will stop the tracking code from being over­writ­ten every time your WordPress theme updates.

Fact

A WordPress child theme is a theme that inherits features from another, “more important” theme. This other theme is called the parent theme.

To add the code to your WordPress website, go to the theme editor and search for header.php. Add the Google Analytics tracking code directly before the closing </head> tag in the editor.

Click on “Update file”. You have now added your Google Analytics tracking code to WordPress.

Google Tag Manager for WordPress

You also have the pos­sib­il­ity to add Google Analytics to WordPress by using Google Tag Manager.

Google Tag Manager is a system to manage tags and code on your website to avoid you having to edit the code directly in WordPress. This reduces the chance of errors and lets you edit it even if you have no developer skills. To make the in­stall­a­tion easier, you can get Google Tag Manager as a WordPress plug-in.

Download the plug-in, then install and activate it. Create your Google Tag Manager account and set up a new container. Go to the admin tab of your Google Tag Manager dashboard and look for a row of char­ac­ters beginning with “GTM”. This is your container ID. Copy it. Go back to your WordPress site and access the settings of the Google Tag Manager tab. Here, paste your Google Tag Manager ID into the relevant field.

Every tag that you put into Google Tag Manager will now also work on your WordPress website thanks to the plug-in.

Managed Hosting for WordPress
Create your site with AI, we manage the rest
  • Stress-free, no matter your skill level with easy AI tools
  • Full cus­tom­isa­tion with themes and plugins
  • Hassle-free updates and less admin

Google Analytics and data pro­tec­tion

Current European data pro­tec­tion laws (the GDPR) mean that Google Analytics can no longer collect data without first getting consent from site visitors. You must therefore take a few pre­cau­tions to ensure that Google Analytics is using data collected from your site in a way that complies with this data pro­tec­tion law.

1. Sign a valid data pro­cessing agreement with Google

You can sign a data pro­cessing agreement directly through your Google Analytics account. For more in­form­a­tion about this agreement, go to this Google support page.

2. Activate IP an­onymisa­tion

By adding an “_an­onym­izeIp” function to your tracking codes in the JavaS­cript library “ga.js”, you can ensure that the IP addresses of your visitors will never be com­pletely saved. The final digits, which allow iden­ti­fic­a­tion of the computer itself, will be replaced with a series of zeros. For more in­form­a­tion about IP an­onymisa­tion, go to this Google support page.

3. Avoid the “User ID” function

In the latest version of Google's “Universal Analytics”, even more data are processed than with the standard version. You should make sure that the User ID function is de­ac­tiv­ated. This function allows tracking across devices by letting site owners follow User IDs even more ef­fect­ively, which does not comply with German data pro­tec­tion laws.

4. De­ac­tiv­ate the target group (or “re­market­ing”) function

You can change this setting in the Google Analytics options. For more in­form­a­tion, go to this Google support page.

5. Let users de­ac­tiv­ate add-ons

Visitors have the pos­sib­il­ity to opt out of their user data being saved. This works with all common browsers, but not on mobile devices.

6. Let users opt out of cookies

With a simple click, users can block analytics tracking, including on mobile devices. A guide on im­ple­ment­ing this using JavaS­cript (Disabling tracking) can be found in this Google article.

7. Limit data retention periods

Limit data retention periods in the settings (to 14 months maximum) and de­ac­tiv­ate the “Reset on new activity” function.

8. Explain your data pro­tec­tion

In your data pro­tec­tion policy, make sure you clearly explain to your users if you use Google Analytics, and if so, what you do with it. Make sure to also detail the above-mentioned points, i.e., the data pro­cessing agreement, IP an­onymisa­tion and opt-out options (for browser plug-ins and cookies).

Tip

There are even more tools to analyse your site’s per­form­ance. Some al­tern­at­ives to Google Analytics place more im­port­ance on data pro­tec­tion.

Go to Main Menu