As we all know, Google Analytics is a great tool to track and report website traffic. It will give you a deeper understanding of your customers and everything you need to analyze data for your business.

If you’re looking to use Google Analytics to monitor your WordPress site, then you will need to install a Google Analytics tracking cookie.

This can be done with three different, but very simple methods: Using a plugin, inserting the tracking code into the header or footer of your site with a plugin, or by manually inserting the code into your header.php or footer.php files of your WordPress theme.

Regardless of your level of expertise with WordPress or coding, adding a Google Analytics tracking cookie is easier than you may think.

How to find your website’s tracking code

  1. Sign in to your Analytics account.
  2. Click Admin.
  3. Select an account from the menu in the ACCOUNT column.
  4. Select a property from the menu in the PROPERTY column.
  5. Under PROPERTY, click Tracking Info > Tracking Code. Your Google Analytics ID is displayed at the top of the page.

Google Analytics Tracking Code

The tracking code will be displayed in the middle of the page and look like this,

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-12345678-1');
</script>

 

1. Using a WordPress Plugin

If you’re not comfortable playing around with your theme or working with code, you can simply install your Google Analytics tracking cookie by using a WordPress plugin. A great plugin you can use to achieve this is Google Analytics for WordPress by MonsterInsights.

Google Analytics for WordPress by MonsterInsights

Google Analytics for WordPress by MonsterInsights is the most popular Google Analytics plugin for WordPress. It has over 2 million active installations! Using a plugin such as this one is the easiest way to install the Google Analytics tracking cookie—making it a perfect choice for beginners. Plus, it is free to install!

After installing the plugin, click on Insights in your WordPress Admin menu to bring up the MonsterInsights setup wizard. You will be asked to choose a category for your website before prompting you to connect the plugin to your Google Analytics account.

Then, you will be asked to allow MonsterInsights to access your Google Analytics account. After selecting the profile you want to track, you can finish the process by completing the authentication. Now you’re all ready to go!

Here’s a quick 1 minute video tutorial on how to setup and configure the plugin.

Remember, it can take up to 24 hours for the reports to populate. After that, you’ll be able to start monitoring and analyzing your website’s data.

2. Insert the Tracking Code in the Header or Footer with a Plugin

Another option to installing your Google Analytics tracking cookie is by using a plugin, such as Insert Headers and Footers, to embed it straight into your header or footer. This method is very similar to the last, but it has multiple purposes that can benefit you.

Insert Headers and Footers plugin by WPBeginner

The Insert Headers and Footers plugin allow you to insert codes such as Google Analytics, custom CSS, and Facebook Pixel to your WordPress site’s header and footer without editing your theme files. It makes inserting scripts simple without having to deal with dozens of different plugins.

After installation and activation, you will find the Inserts Headers and Footers plugin under Settings. Here, you will paste the Google Analytics tracking cookie code into the headers section.

Paste the Google Analytics tracking cookie code into the headers section

Click save and you’re done!

3. Manually insert the tracking code into header.php or footer.php

Finally, the last way to install your Google Analytics Tracking Cookie is by inserting the code into the header.php or footer.php files of your WordPress theme. We would only recommend this method to those that are comfortable working with coding. Please note that the code will disappear if you decide to switch or update the theme, which is why we usually recommend plugins.

To add the code in your header.php or footer.php file, in your Admin Dashboard go Appearance » Theme Editor. Then click on the header.php file to edit and paste the Google Analytics tracking cookie code right before the closing </head> tag. Click save and you’re ready to go!

Insert the tracking code before the closing head tag

If you want, you can also add the Google Analytics tracking cookie code to the WordPress functions file. This will automatically add the tracking code to every page on your WordPress site. To complete the process, you will need to add this code to your theme’s functions.php file:

<?php

add_action('wp_head', 'wpb_add_googleanalytics');

function wpb_add_googleanalytics() { ?>

// Paste your Google Analytics tracking cookie code here

<?php } ?>

Don’t forget to save your changes!

Which Method Should You Use?

This all really depends on your level of expertise and how comfortable you are working with code. For absolute beginners, we recommend using the first method and installing the Google Analytics tracking cookie with a plugin. If you’re looking to add other custom CSS and codes to your header and footer without having to touch your theme’s code, then the second option will be great. For the more advanced users, the third option is open; however, we don’t always recommend it if you’re looking to change or update your theme in the near future.

Regardless of which method you use, each one will get the job done. Now you’re done and ready to take full advantage of everything that Google Analytics has to offer. It’s a powerful tool that will allow you to track visitors to your WordPress website. You will now be able to effectively view the real-time view of your traffic, understand your users, explore where your users are coming from, and many more!

Published by Hans Desjarlais

Founder @ Themely, entrepreneur and travel addict. Always learning, maverik at heart, speaks 3 languages and hope's to go to space one day.
css.php

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match