Adding Google Analytics to WordPress can be done by using one of four methods:
- Adding Google Analytics to WordPress using inline tracking code.
- Adding Google Analytics to WordPress using plugins.
- Adding Google Analytics to WordPress using Google Tag Manager (GTM) via inline code.
- Adding Google Analytics to WordPress using GTM plugins.
There are a few things you’ll need to have in place before you start:
- A Google Account
- A Google Analytics Account
- If using Google Tag Manager (GTM), you need a GTM Account and Container with the GA pageview tag installed
Critical – Plan the best method for adding Google Analytics to WordPress
Take some time to research and consider which method is going to work best for you. T
his would warrant a separate blog post, but broadly speaking, be guided by your requirements, the resources available to you and the level of technical skills at your disposal.
Smaller sites with limited technical resources may opt to use plugins, while larger enterprise WordPress sites with technical teams will likely prefer an inline code approach, but…
There is no right or wrong way.
Let’s dive into the methods available to you, starting with Inline Tracking Code.
Method 1: How To Add Google Analytics to WordPress With Inline Tracking Code
If you’re nerdy, you can do this yourself, but when making inline tracking code changes, it’s important to:
- Always consult your theme documentation before proceeding.
- Remember that editing code is not without risk. Always make a copy of your header.php file with a different name before you make and save any changes to your WordPress site.
E.g. make a copy of your header.php file and rename the original header-old.php That way, if you break the code, you have a fully working version to revert to 😊.
It’s also best practice to work on a child theme of your site. This is because when you update your theme, the files you edited will be overwritten, removing your Google Analytics tracking ☹
If this sounds overwhelming or too challenging, follow the instructions for using plugins instead for a simpler life.
The 3 Steps to Add Google Analytics to WordPress with Inline Tracking Code:
- Step 1. In your WordPress theme, you’ll need to locate the template where the HTML <head> information is located. It’s commonly found in the php file.
- Step 2. In Google Analytics, copy your GA Property tracking code (admin > PROPERTY > Tracking Info)
- Step 3. Edit the php file using WordPress’ editor (admin > settings > editor) and add the tracking code in the opening <head> section of the site.
But, let’s take a look at the pros and cons of adding Google Analytics to WordPress via Inline tracking Code:
Google Analytics Inline Pros
- Locates the tracking code according to Google best practice in your HTML
- You’ll have full control of your tracking code
- Code is customisable
Google Analytics Inline Cons
- Must be done in your child theme
- Requires you to update code changes manually
- Requires technical skill for customisation and can be easily misconfigured
- Adding lots of inline tagging can bloat the HTML source code, adversely impacting page speed performance
Find more support with the guides below:
Method 2: How To Add Google Analytics to WordPress With Plugins
For many small operations and one-person setups, the technical challenges and extra customisation requirements when using inline code are blockers.
As such, adding Google Analytics to WordPress via Plugins can be super useful in these instances.
Pros & Cons of Adding Analytics to your WordPress site via a Plugin:
But first, what are the pros and cons of using plugins to add Analytics to your WordPress site?
- Easy to use
- Offers a wide range of built-in ‘advanced’ customisation deployed at the click of a button, e.g. Event tracking.
- Offers some useful extras like dashboard reporting in WordPress
- Frequently updated by third parties
- Some offer GTM support 😊😊😊
- Limited tracking code customisation
- May lack specific features you need
- May negatively impact site performance (too many plugins)
- Free plugins might lack good support, leaving you in limbo when a problem strikes
- Adding additional analytics tracking tags will require even more plugins (unlike using GTM)
To get you started, we checked out three WordPress plugins with a high volume of downloads and good user ratings.
- Widely used: 1+ million active installs
- Good selection of dashboards to view in backend or to add to posts
- Advanced Google Analytics configuration settings with full code customisation options
- Event tracking
- Custom Dimension tracking
- GTM tracking
- Accelerated Mobile Pages (AMP) tracking for GTM
- E-commerce support
- Limited support
You probably noticed this plugin includes Google Tag Manager integration – so it could be used for Method 4: Add Google Analytics to WordPress using GTM plugins too.
- Reasonably priced with support included
- One-click installation
- Easy to use
- Dashboards for page level, social media, custom posts and real-time stats reporting
- Publish dashboards to the WordPress frontend page to share with teams
- Enhanced E-commerce tracking/reporting with WooCommerce or Easy Digital Downloads
- Automated email reporting
- Custom Campaign reporting
- Paid plugin
- Lack of advanced configuration settings
- No GTM option
This plugin is for e-commerce sellers using WooCommerce
- Good support
- Tracks Enhanced E-commerce on WooCommerce sites
- Includes Shopping Behaviour Report, Checkout Behaviour Report, Product Performance Report, Sales Performance Report
- Option to upgrade to paid version with advanced enhanced e-commerce tracking and full support (great value)
- Not recommended with GTM
- Requires support if using a child theme
- Out of the box version does not provide for customised store or store using WordPress child theme. Check feature support carefully.
Tatvic’s plugin packs a lot of power!
That wraps up the plugin options so next, we’ll look at some of the Google Tag Manager options for WordPress.
Method 3: Add Google Analytics To WordPress Using Google Tag Manager Inline Code
Implementing Google Tag Manager tags inline follows a similar process to adding Google Analytics inline.
Follow these steps to add Analytics to WordPress using Google Tag Manager Inline Code:
- Sign in to your GTM Account https://tagmanager.google.com/.
- Locate your GTM container which contains your GA Tag.
- Click on your GTM ID.
- Copy the code which goes in the <head> of your WordPress template.
Follow the instructions for adding GA inline code to WordPress to add your GTM container to WordPress.
Pros and Cons
The pros and cons are pretty much the same as adding GA code inline.
Method 4: Add Google Analytics to WordPress Via Google Tag Manager Using Plugins
Plugins are a quick and efficient method of adding Analytics to WordPress and here are two popular plugins to consider if you’re going down the Google Tag Manager route:
DuracellTomi’s Google Tag Manager for WordPress
- Works out of the box and is easy to set up
- Tracks WordPress post/page titles, dates, category names, tag names, page ID, author ID, author names, logged-in status and more.
- Event Tracking for Contact 7 forms and social media
- Weather and browser / OS/device data tracking (beta)
- Classic E-commerce
- Enhanced E-commerce tracking (beta)
- Google AdWords Remarketing
- Scroll tracking
- Tag blacklist/whitelist options
- YouTube, Vimeo and Soundcloud Event tracking
- Reported problems with social media tracking
- Free plugin so there may be some issues with answering support requests
- Requires editing the WordPress theme to install it in the HTML <head> of your WordPress site templates following Google’s best practice
Metronet Tag Manager
- Simple, frills-free
- Allows you to add Event tracking to WordPress links
- Allows you to easily add HTML IDs to any WordPress content using the WordPress page editor
- Plugin text copy looks outdated
- Requires some technical knowledge to create and add dataLayer.push code to HTML for Google Analytics Event tracking
So, there you have it, 4 different methods for adding Google Analytics to your WordPress site. If you have any questions on this or have something useful to add which will help others based on your experience, don’t be shy – drop a comment below!
If you’re getting started with Google Analytics and are looking for some help, why not get in touch. You can find out more about our Google Analytics services here or feel free to call us on 01273 733433 or get in touch using the form below. We’d love to help!