skip to Main Content

How to add Google Analytics to your WordPress website

In this post, I’ll share how to add Google Analytics to WordPress. Google Analytics is a free and powerful tool that shows you insights about your website visitors. You can then use those insights to be more targeted with your digital marketing efforts. If you’re not already familiar with this tool, you should learn more about Google Analytics before going further. However, if you’re reading this post, there’s a good chance you’re comfortable with Google Analytics, so let’s dive into how to get it set up on WordPress.

How to add Google Analytics to WordPress without a plugin

In the sections below, I’ll show you how to install Google Analytics on WordPress without the use of a plugin. I’ll show you two methods: One with Google Tag Manager, and one without Google Tag Manager. For the method without Google Tag Manager, we’ll use the WordPress header.php file instead. In those same steps, you’ll see exactly where to put the Google Analytics code in WordPress. If you’re looking specifically for those steps, jump down to that section.

Here we go!

How to add Google Analytics to WordPress with Google Tag Manager

  1. Make sure you’ve installed Google Tag Manager on your WordPress website. If you need steps on how to do that, check out our tutorial.
  2. Make sure you have a Google Analytics account. If you don’t, you’ll want to head over to getting started with Analytics first.
  3. Log in to Google Tag Manager.
  4. Select New Tag on the Workspace tab.
    New Tag on Google Tag Manager

    Click on the image above to access a high-resolution picture.

  5. Deleted the text “Untitled tag” and give your tag a name. This might be “Google Analytics” or something similar. If you think you’re going to add a lot of tags to your website, you may want to keep things organized by using Google Tag Manager naming strategies.
    Untitled and new tag on Google Tag Manager
  6. Select the tag icon under the Tag Configuration section.
  7. Select Google Analytics tag from the list.
    Choose tag in Google Tag Manager
  8. Make sure the Track Type is set to Page View.
  9. Under Google Analytics Settings, select New Variable.
  10. Input your Tracking ID. To get your Tracking ID, go to Google Analytics and navigate to Admin > Property > Tracking Info > Tracking Code.
    Tracking ID on Google Analytics
  11. Rename the variable to, “Google Analytics Settings”.
  12. Save the tag.
  13. Select the trigger icon under Triggering.
  14. Select the plus (+) symbol in the upper right corner.
  15. Select Page View > Page View under Choose trigger type.
    New trigger on Google Tag Manager
  16. Make sure the This trigger fires on section is set to All Page Views.
  17. Name the trigger.
  18. Save the trigger.
  19. Select the trigger.
  20. Save your tag.
  21. Select the Preview button to turn on preview mode. Once preview mode is activated, you’ll see a notification across the top of Google Tag Manager.
    Preview mode in Google Tag Manager
  22. Open a new tab or browser window and go to your website.
  23. Make sure the Google Analytics tag is listed under the Tags Fired On This Page section of the preview panel, located at the bottom of the browser window.
    Google Tag Manager preview mode turned on while viewing the website
  24. Open another browser window and go to your Google Analytics account.
  25. Go to the Overview under the Realtime section.
  26. Make sure you can see at least one Pageview. This means you set up the Google Analytics tag correctly, and that traffic is being recorded.
  27. Go back to Google Tag Manager and select Leave Preview Mode.
  28. Make sure the preview mode banner goes away.
  29. Select the Submit button.
  30. Enter the Version Name and Version Description.
    10 - Publish Version
  31. Select Publish.
  32. In a new window or tab, go to your website.
  33. Enable Tag Assistant.
  34. Refresh your browser window.
  35. Access Tag Assistant and make sure Google Analytics has been correctly installed on your website. If it’s installed correctly, the Tag Assistant will put a green or blue tag next to Google Analytics. The blue tag will show when you’re using Google Tag Manager because it’s a non-standard implementation.
    Google Tag Assistant
  36. Go to Google Analytics.
  37. Access the Overview report of Realtime reports.
  38. Check and make sure the recent visit to your website has been recorded. This means Google Analytics has been properly installed on your WordPress website.

How to add Google Analytics to WordPress using header.php

  1. Make sure you have a Google Analytics account. If you don’t, you’ll want to head over to getting started with Analytics first.
  2. Log in to Google Analytics.
  3. Select the Google Analytics account and property you want to set up.
  4. Navigate to Admin > Property > Tracking Info > Tracking Code.
  5. Under the Website Tracking section, copy the script listed under Global Site Tag.
    Global Site Tag in Google Analytics
  6. Log in to WordPress.
  7. Navigate to Appearance > Editor.
    Note: Some themes offer a code injection option, where you’re able to add scripts to the <head> section of header.php, using a special section of the theme settings. It’s fine to use this functionality. If you’re going to do so, jump down to step 10.
  8. In your theme files, access header.php.
  9. Paste the code snippet into the <head> section of header.php.
  10. Save the update.
  11. In a new window or tab, go to your website.
  12. Enable Tag Assistant.
  13. Refresh your browser window.
  14. Access Tag Assistant and make sure Google Analytics has been correctly installed on your website. If it’s installed correctly, the Tag Assistant will put a green or blue tag next to Google Analytics.
    Google Tag Assistant
  15. Go to Google Analytics.
  16. Access the Overview report of Realtime reports.
  17. Check and make sure the recent visit to your website has been recorded. This means Google Analytics has been properly installed on your WordPress website.

How to add Google Analytics to WordPress using a plugin

Adding Google Analytics to your WordPress website with a plugin is something I’d recommend to someone new to WordPress or someone who would rather stay away from the more technical activities of a website (like adding or modifying code). There are some fantastic Google Analytics plugins for WordPress websites. MonsterInsights and ExactMetrics are some of the best and most popular plugins for adding Google Analytics to WordPress.

To add Google Analytics to WordPress using a plugin:

  1. Make sure you have a Google Analytics account. If you don’t, you’ll want to head over to getting started with Analytics first.
  2. Log in to WordPress.
  3. Go to Plugins > Add New.
  4. In the Search plugins field, start typing a plugin name and wait for the results to show.
  5. When you see the plugin you want to use, select the Install Now button.
  6. Follow the setup steps or plugin documentation to complete the plugin setup. You may need to visit the plugin’s website to get the documentation.
  7. In a new window or tab, go to your website.
  8. Add and enable Tag Assistant.
  9. Refresh your browser window.
  10. Access Tag Assistant and make sure Google Analytics has been correctly installed on your website. If it’s installed correctly, the Tag Assistant will put a green or blue tag next to Google Analytics.
  11. Go to Google Analytics.
  12. Access the Overview report of Realtime reports.
  13. Check and make sure the recent visit to your website has been recorded. This means Google Analytics has been properly installed on your WordPress website.

Wrap up

What method would I suggest you use to add Google Analytics to your WordPress website? When I’m working with WordPress websites, I like limiting the use of plugins, for many reasons. With this in mind, I would recommend adding Google Analytics to WordPress without the help of a plugin. To go a step further, I recommend adding Google Analytics through Google Tag Manager, due to how easily these tools integrate together and the added benefits that come along with Google Tag Manager.

If you need someone to step in and implement Google Analytics on your WordPress website, we’ve got you covered. Check out our WordPress SEO essentials service for more information on how we can help. If you have any questions about what was covered in this article, reach out to us.

Josh Gellock

Josh is the SEO and Content Strategist at Expander Digital, an SEO studio he founded in 2014. He's been in the SEO space for over seven years and helps businesses drive website traffic from organic search. When he’s not meeting with clients, you can find Josh spending time with his children or on a bike.

This Post Has 0 Comments

Leave a Reply

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

Back To Top