Marketing, SEO

How to Setup Google Analytics on WordPress Website

by Tomasz M.
Nowadays statistics are very important for companies. Especially when this is your main marketing channel to generate revenue.

Google Analytics can help you with gathering useful data about users on your website, grow sales, improve your services. Google Analytics is free, so why do not use it if there are no drawbacks?

In this article, I will show you how to start using Google Analytics on WordPress website.

Create account and service in Google Analytics Dashboard

Go to Google Analytics Website. Click create an account.

In the first step, you can use your existing Google account to use as Google Analytics account.

Click Admin, in the Account column, use the drop-down to select the account you want your website to be added too or create a new account.
Select Website option and Enter the Account Name, Website name, and URL. One account can have many websites.

Then Select Industry Category and Country.

Click Get Tracking ID, accept Service Agreement and copy Website tracking code like this one for example:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-106404841-1', 'auto');
ga('send', 'pageview');

</script>

The most important part of the code is your websites unique tracking ID. In this example it is set to UA-106404841-1

There are few ways that you can integrate Google Analytics into your website. Bellow I describe them all.

Google Analytics by MonsterInsights

  • Install Google Analytics by MonsterInsights as any other plugin and activate it.
  • Click on Insights on the left menu of WordPress admin panel.
  • Click authenticate with Google Analytics to allow the plugin to fetch data.
  • New box will show up - click next and then click the "Get Google Code".

google analytics

  • In the new window select account related to Google Analytics dashboard and log in.
  • Give plugin permissions to view and edit Google Analytics data by clicking Accept.
  • Copy the code you see on the screen. Example: 4/yJ5cM7CbTgtYTix5Irxy8GUdhQma_6v2Ad_LQwQponM.
  • Then, you can close this browser window.
  • Enter it into the "Paste Google Code" box and click next.
  • Select proper website in "select profile" dropdown box and click next.
  • Then, click close.

Now you will have new stats in WordPress dashboard Insights -> Dashboard. Lots more information will be accessible in Google Analytics Dashboard. Give Google some time to gather your website data, probably around 24h.

monster insights

Google Analytics Dashboard for WP (GADWP)

  • Install GADWP as any other plugin and activate it.
  • Click on "Google Analytics" inside the left sidebar of WordPress admin panel.
  • Click "Authorize Plugin".
  • Then Click Get Access Code. In the new browser tab select account related with Google Analytics dashboard and log in.
  • Give plugin permissions to view and edit Google Analytics data by clicking accept.
  • Copy the code displayed on the screen. For example: 4/yJ5cM7CbTgtYTix5Irxy8GUdhQma_6v2Ad_LQwQponM.
  • Then, you can close this browser tab.
  • Enter the code in the previous window "access code" box and click save.

wordpress developers

  • Select proper website in  "select view" dropdown and save changes.

Now you will have a preview of stats in WordPress dashboard and lots of data in Google Analytics. Give Google some time to gather your website data (around 24h).

Manually add tracking .js code to your WordPress theme header.php

If you have skills to add code manually you can do this by adding code to header.php file of your theme.

Remember:If you have blocked file editing from wordpress wp_config.php or by some plugin - you can't use this method. Don't use it when you have plugins for that installed. Always use child theme and its header.php file to not lose your changes after theme update. If you dont have header.php in your child theme - you must create one by FTP.

You can do this in WordPress Admin Panel -> Appearance -> Editor. Find and click header.php on the right side of the screen.

Then paste generated code right above </head> tag and click Update file.

worpdress developers

Manually add tracking .js code to your WordPress theme as a function

If your theme doesn't have built-in functions in Appearance -> Customise or in other theme settings, you can manually add tracking code to functions.php file of the theme.

The upside of this method is that you can track only for example not registered users or users of some role if you want.

Decoration

Need Plugin Customization?

Our Experts can handle any customization or development at a resonable price.

Remember: If you have blocked file editing from WordPress in wp_config.php or by a plugin - you can't use this method. Don't use this method if you are already using a plugin that integrates GA into your website. Always use the child theme and its functions.php file to edit a theme, that way you won't lose your changes after theme update.

Go to WordPress Dashboard -> Appearance -> Editor. Find and click functions.php on the right side of the screen.

Then paste generated code at the end of the file and click "Update file" button.

Conclusion

So there you have it, those are the 3 most common ways of adding the Google Analytics into your WordPress website. If you want to learn some more advanced techniques, like tracking only not logged in users. Let me know and I will prepare another article on this topic.

Do you use any other method on your website? What good practices do you know to grow your sales with WordPress? I hope you had a good read.

Tomasz M.
(Wordpress Expert)

Disqus Comments

Reading time 5 minutes

This website uses cookies to ensure you get the best experience. More info I agree