Adding Google Analytics to WordPress can be done by using one of four methods:
- Add Google Analytics to WordPress using inline tracking code.
- Add Google Analytics to WordPress using plugins.
- Add Google Analytics to WordPress using Google Tag Manager (GTM) via inline code.
- Add 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 GTM, you need a GTM Account and Container with the GA pageview tag installed
Critical – Plan Your Strategy
Take some time to research and consider which method is going to work best for you. This 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 Google Analytics.
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 process is as follows:
- 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.
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
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. WordPress GA Plugins can be super useful in these instances.
- 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 GTM 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 post 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 GA options. Next, we’ll look at some of the GTM options for WordPress.
Method 3: Add Google Analytics To WordPress Using Google Tag Manager Inline Code
Implementing GTM tags inline follows a similar process to adding GA inline. Follow these steps:
- 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 GA to WordPress Via GTM Using Plugins
Plugins are a quick and efficient method of adding GTM to WordPress. Here are two plugins to consider if you’re going the GTM route:
DuracellTomi’s Google Tag Manager for WordPress
- Works out of the box and 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 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
That’s it, 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. Feel free to call us on 01273 733433 or get in touch using the form below. We’d love to help!