How to Add Website Analytics to WordPress

Have you launched a new WordPress site in the recent past? One of the first things any new website should add immediately is website analytics. Analytics gives you a real-time overview of who is visiting your website, and what are the sources for those visits, also.

Though, it’s no secret that WordPress doesn’t do this out of the box. As such, if you’re a WordPress user – you will have to find an alternative solution to add website analytics to your blog.

And in this article, we will explain why analytics are important, but also talk about GDPR, cookie notices, and our recommendations for the best analytics platforms out there.

Why are website analytics important?

Website analytics provides you with the means to understand why visitors come to your site. But, also, where do they come from (referral sources), and which pages are being visited the most. Just by knowing which specific content on your site is performing the best, you can adjust your strategy to produce similar content in the future.

Likewise, analytics can provide data such as how long a visitor is staying on your pages. If you see that the bounce rate is extremely high, you can make adjustments and improve the page so that visitors don’t immediately leave your site.

Google Analytics report sample

In this example, we have a website that has gotten 23,000 unique visitors in the last 28 days. Out of those, around 20,000 bounced (left the website without visiting other pages). And, on top of that, session duration was also relatively low – only 40ish seconds. This report alone can inspire you to take a hard look at why this is happening.

Another important reason to use website analytics is the ability to monitor acquisition channels. In other words, be able to see which websites, social platforms, and search engines that send you website traffic.

This is useful information because it gives you an overview of who is talking about the content that you’re publishing. And, in the long run, it gives you an opportunity to build relationships with other bloggers and content producers who have shared your content.

Additionally, website analytics can shed light on things like:

  • What is the primary device users use to come to your website? E.g. Desktop or Mobile.
  • Conversion goals. E.g. Does a user check your product page after visiting a blog post?
  • From which countries do people visit your website the most? This can give you insight into whether you should add localization to translate your content into other languages.

And last but not least, website analytics is important if you ever plan to do advertising on your site. The only way to prove the legitimacy of your traffic and site popularity is directly through analytics.

Analytics & GDPR

So, now that we know why analytics are important, let’s talk about another equally as important topic, and that’s GDPR. The General Data Protection Regulation is an EU law specification that aims to protect the privacy of visitors coming to your website. The sole purpose of GDPR is to ensure that users have the choice to opt-out of being tracked.

Analytics & GDPR

This law can be quite confusing, even for law experts! So, let me break it down in simple language.

If you use an analytics platform such as Google Analytics on your website, you must provide a cookie notice which implicates that you’re tracking user data. You have to do this because Google Analytics is a US-based service, and according to GDPR – for any sensitive data about EU citizens to be stored in the US, the EU citizen has to give permission for it.

That’s the general gist of it.

At the very least, you will need to use a cookie notice plugin and generate a privacy policy page. In WordPress, you can go to Settings -> Privacy from the admin dashboard to generate a Privacy Policy template.

Do you need to show a cookie notice?

You can’t go further than a handful of websites to see that every single one has a “cookie notice” popular or modal box added to it. The goal of this notice is to ensure that users give consent to be tracked as required by GDPR.

Now, for some websites, the notice is quite small and doesn’t provide any checkboxes to tick. But for larger publications, such as news sites, you’re often asked to consent to specific tracking methods. This is because that data is then used to serve you advertisements and other promotional media.

Do you need to show a cookie notice

But, the real question is – can you avoid adding a cookie notice to a website? Well, the short answer is yes, you can. However, this is only possible by using privacy-friendly analytics platforms. Or, as an alternative, you use a platform that is hosted inside the EU, and all the data you track is hosted on EU-based servers. Sounds a little bit complicated, right?

It’s no secret that Google Analytics has come under a lot of scrutiny in recent times. The French data protection authority deemed Google Analytics illegal, as did the Austrian data protection authority. Of course, this doesn’t mean that you cannot use Google Analytics. All it means is that it is 100% mandatory to add a cookie notice which lets your site visitors provide consent for their data to be tracked and stored.

But, in the light of these regulations – this article on adding website analytics to your site is also going to showcase some privacy-friendly alternatives. In other words, if you don’t want to show a cookie tracking notice, we have something in store for you as well.

The best website analytics platforms

The nice thing about WordPress is that you have a lot of options for analytics tools to use. Just by going to Plugins -> Add New and searching for “analytics” will return hundreds of results!

WordPress analytics plugins search

So, the question is – which of these solutions is the best for you? The following section is dedicated specifically to answering that question. Though, we will also consider everything we have learned so far in this article. Especially the notion of protecting your visitor data.


#1: Google Analytics

Google Analytics

At the time of writing this, Google Analytics has a whopping 86% market share in the traffic analytics context. It is undeniably the most popular tracking solution on the web. And, it has been for many years.

As for the reasoning, it’s quite simple. Google Analytics is part of Google services, which makes it easy to integrate everything into one unified dashboard. Additionally, the analytics platform itself provides an extensive list of features to help you analyze the exact data you’re after.

If you’re going to add Google Analytics to your WordPress site, we recommend using the official Site Kit by Google plugin. This kit includes features like access to Search Console, Analytics, PageSpeed Insights, and also AdSense. So, a large proportion of the most commonly used webmaster services as provided by Google itself.

Here are some of the features of the Site Kit plugin:

  • Very simple to set up. Upon activating the plugin, you will be taken through an onboarding process to connect all your Google services.
  • Get access to analytics reports directly from the WordPress dashboard.
  • Doesn’t require editing any code or modifying files in your theme. Just connect and you’re ready to go.

The only requirement is that you have a Google Analytics account.

Download: wordpress.org/plugins/google-site-kit/

How to add Google Analytics without a plugin

It’s understandable if you don’t want to use a plugin for this specific purpose. Not much changes if you add the analytics code to your site manually, it just means you will have to see all the reports from the official dashboard. Either way, this is how you add the tracking code without a plugin.

#1: Create a new account or use an existing one.

Once you have your account ready, you can go to the Google Analytics dashboard and locate the Admin panel. Here you will have the option to “Create a New Property”.

create a google analytics property

You will have to complete a few steps from this dashboard. Such as adding a property name, and specifying that it is intended for a website. And, finally, you will need to specify the website address which you wish to track. In this case, it is going to be your WordPress site.

Once you’re done, the onboarding process will redirect you to a page that contains the Global Site Tag (gtag.js) information. It looks something like this:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-42068213-9"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-42068213-9');
</script>

#2: Add the Global Site Tag to your header file.

Once you have the tracking script code copied, you can head over to the WordPress admin dashboard. From there, go to Appearance -> Theme File Editor. This page lets you modify your theme files. The specific file you need to locate is header.php – on the right-hand side.

modifying header file WordPress

Once you have it open, you need to find the closing header tag, in this case, it is </head>. Right above this tag, you copy and paste your analytics code. You can see an example of this in the screenshot above. Once copied and pasted, click Update File and you’re done!

You can go back to the Google Analytics dashboard to verify that the tracking script is working. That’s it.

#2: Matomo Analytics

Matomo Analytics

So, because we talked about privacy and data regulations, it is worth mentioning Matomo analytics. It is commonly referred to as the go-to alternative for Google Analytics. Though, the main difference between both platforms is that Matomo puts an emphasis on making sure that your visitor data remains private. Additionally, the data gathered by Matomo is not shared elsewhere, giving you full control over how you use it.

In fact, Matomo provides additional tools to further encrypt the data about your site visitors. This is useful because it eliminates the need to use any cookie notices or other consent-based scripts on your site. The in-built GDPR manager can help you set up your analytics in a way that’s friendly to your visitors, but also give you a reliable means to track site visitors.

Download: wordpress.org/plugins/matomo/

#3: Koko Analytics

Koko Analytics

The last website analytics solution we recommend is Koko. This is the perfect solution for projects where you don’t need in-depth analytics. Koko is a lightweight solution that emphasizes user privacy. You still get data about who is coming to your website, the referring pages, and also total clicks for pages, but none of it is tracked through cookies.

Koko Analaytics dashboard

Because the plugin tracks so little data, the script that does the tracking leaves a minuscule footprint on your site. And, it will go a long way to ensure that your WordPress website loads quickly.

Download: wordpress.org/plugins/koko-analytics/

Closing words

Finding the right analytics platform for you is largely an independent choice. Because of the way that various regulations enforce their rules, we are seeing a huge influx of new platforms providing such a service. So, in the end, you have to consider how important it is for you to track certain data, and whether a simpler solution is more appropriate for your needs.

I believe this post covers the absolute necessities of getting started with tracking your website visitors. Should you need additional help with setting things up, don’t hesitate to reach out and we will do our best to help.

Leave a Reply

Your email address will not be published. Required fields are marked *