In this blog, we cover why you should add Google Analytics to your WordPress site, and show how to do it – both with/without a plugin. All you need to do first is set-up a Google Analytics account.
why add Google Analytics on WordPress
Google Analytics is a free web analytics service which tracks your website data and provides various stats and reports.
Google Analytics collects a wide range of useful information including:
- How people find your site (for example, via organic search, social media or paid advertising)
- When your site is busiest and quietest
- Which webpages are most popular
- How long people spend browsing your site
- Which devices and browsers visitors are using
- … and much more!
By collecting this information, you can base any decisions about updating or improving your website on real data. This gives you the best chance to increase your traffic and engagement, and therefore to maximise your WordPress website’s success.
how to add Google Analytics to WordPress with a plugin
Whether you’re a WordPress beginner or just like to keep things as simple and straightforward as possible, adding Google Analytics with a plugin is a great option.
With a Google Analytics plugin, you can also rest assured that your WordPress website data is always being collected, even if you change your design or theme.
Used by more than a million WordPress sites, MonsterInsights is the most popular Google Analytics plugin. The basic version is free, but you may want to add paid features such as tracking e-commerce sales.
Before installing MonsterInsights, make sure to back-up your site – just in case anything goes wrong! We explain how to back-up on WordPress in our Ultimate WordPress Optimisation Guide.
Once MonsterInsights has been added to your site, you’ll find ‘Insights’ appears in your WordPress dashboard menu. Click on this to start the setup wizard and connect MonsterInsights with your Google Analytics account. You’ll also need to select your preferred settings – the default option is suitable for most websites.
It’s that simple – Google Analytics is now installed on your WordPress site! You can visit Insights > Reports in your WordPress back-end at any time to see and analyse your data.
how to add Google Analytics tracking code on WordPress
If you’d prefer to add Google Analytics to your site without a plugin, you can manually add tracking code instead.
As always before making any major site edits, make sure to back-up first; we cover how to do this in our WordPress Optimisation Guide.
To set up Google Analytics tracking, log into your Google Analytics account. You’ll need to click on ‘Admin’, then ‘Tracking Info’, and then ‘Tracking Code’. Under ‘Website Tracking’, you’ll find a box containing your Global Site Tag (gtag.js) – highlight and copy this code.
Now go back to your WordPress website dashboard and find your header.php file. Paste in the Google Analytics tracking code, after the <body> tag and before the closing </head> tag.
Finally, click ‘Update File’ to complete the process. Google Analytics will now be recording your website data – just visit your Google Analytics account to see the latest stats.
It’s also worth remembering that if you change your WordPress theme or site design, you may need to re-add the tracking code into your header.php file to ensure data is always being collected.
a note about GDPR compliance
To comply with the UK’s latest data protection laws – also known as GDPR – your WordPress website users MUST agree to have their data tracked BEFORE Google Analytics code is loaded.
You can ask users for permission with a cookie notice. This is simple and easy to add to your WordPress site with a plugin such as Cookie Notice for GDPR & CCPA or similar.
thanks for reading
We hope you enjoyed this blog about how to add Google Analytics to WordPress. For more great WordPress tips and advice, check out our ultimate WordPress optimisation guide, which covers all aspects of how to maintain and improve your WordPress website.