Ways to Add Google Analytics in WordPress Adding Google analytics to your WordPress site allows you to understand how your visitors interact with your website. Google analytics also helps you understand the demographics of your site and which content attracts most visitors. Majority of website owners install Google Analytics to track traffic statistics but there much that can be achieved with Google Analytics. You can track your website bounce rate and figure out how to reduce bounce rate. You can also monitor the sources of visitors by geographical location. In this article I will share some tips on how to add Google Analytics in your WordPress site.

Signup with Google Analytics

 Ways to Add Google Analytics in WordPress

The first step when adding Google analytics in WordPress is to sign up for your analytics account. Go to Google Analytics homepage to create your account. When you sign up and log in you can create new property and add sites to generate the tracking code.

Generating Google Analytics Tracking Code

To track your website you will require either the tracking id or your website tracking code. To generate tracking code you need to follow these steps:

Create new account

Create new account and fill in the details about your site that includes; name of the site, industry, URL of the site and the reporting time zone. You should also choose the data sharing options. A the bottom of this form there is a button to generate the tracking code.

 Ways to Add Google Analytics in WordPress

Get Tracking Code

When you have filled in the details click on get the tracking code. When you click on get the tracking code, you will see the tracking code and tracking ID. These tracking ID and code will be very useful when adding Google analytics to WordPress site.

 Ways to Add Google Analytics in WordPress

Adding Google Analytics to WordPress

There are a number of ways you can use to add Google Analytics to WordPress. One of the most common and easy ways to add Google Analytics to WordPress is using a plugin. Another method of adding Google analytics to WordPress is adding the tracking code above to the WordPress theme. Let us look at each of these methods outlining the pros and cons of each of these methods.

1) Adding Google Analytics in WordPress with a Plugin

There are many plugins that you can use to add Google analytics. Among these plugin Yoast Google  analytics is one I recommend since I have used it and it is good for the job. In my previous post about WordPress On-page SEO for beginners, I outlined how to optimize WordPress for ranking using Yoast SEO plugin.

 Ways to Add Google Analytics in WordPress

Install and Activate Yoast Analytics plugin and go to settings to add your tracking ID. This plugin allows you to add Google tracking ID manually or authenticate with Google. If you want to display Google Analytics in WordPress dashboard, you should not use the manual method to add Google Analytics tracking ID. When you have added Google analytics code you should save the settings and you are done.

Adding Google Analytics Manually

As you can see in the image above, I copied the tracking ID I generated from Google Analytics. If I choose to add Google Analytics using this manual method, I cannot access Google Analytics on WordPress dashboard.  Ways to Add Google Analytics in WordPress

Adding Google Analytics by Authentication

I can alternatively choose to add Google Analytics by authenticating my Google Account. For this option to work you should ensure you are logged in your Google Analytic account. Allow this plugin to fetch data from your Analytics account and copy the code generated by the authentication process back to the WordPress site.

When you complete this process of authentication, you can now choose from a drop down which Analytics account to associate with this site. You should choose one and save the settings to get Analytics setup complete.

 Ways to Add Google Analytics in WordPress When you have added Google Analytics using authentication method you can now get to see a glimpse into your Google Analytics data in WordPress dashboard.

There are also other independent plugins that allow you to see Google Analytics data on your WordPress dashboard. This is a time saving tip for anyone who is keen to follow Google Analytics on a daily basis.

 Ways to Add Google Analytics in WordPress

2) Adding Google Analytics Manually

Another way of adding Google Analytics to WordPress that is rather cumbersome involves adding the tracking code we generated to your WordPress theme. You should start by copying the Google analytics code from your account. It looks something like this:

This code contains your tracking ID, at the point where I have replaced it with ‘TRACKING-ID-HERE'

There are a number of ways you can add this tracking code to your WordPress site that include:

Adding to header.php or footer.php

You can add this code to header.php file by pasting it before the header closing tag. Adding Google analytics tracking code in header.php is an easy and quick way to manually add Google Analytics. You should keep in mind that when you change the theme you will have to add this code on the new theme.

You may add Google analytics this way if you don’t want to have the Google Analytics plugins on your site or there is Google Analytics plugins conflict with other plugins.

Adding to functions.php

You can also add Google Analytics tracking code to your functions.php file. Here is the function to add in your functions.php;

You can place this function in your functions.php file and be careful to replace the Google Analytics code with your own. I have added two Php comments to demarcate the start and the end of the Google Analytics tracking code.

3) Adding Google Analytics in Theme Settings

Another way of adding Google Analytics to WordPress is through the theme settings. It’s important to note that not all themes will have a place to add Google Analytics code but well coded themes should have a place to add header and footer scripts. In the image below this theme I developed allows users to add Google Analytics through themes panel.

 Ways to Add Google Analytics in WordPress

4) Creating Google Analytics WordPress plugin

The last way of adding Google Analytics to WordPress site is by creating a plugin. You can create a plugin instead of adding the tracking code above to functions.php file. Creating a plugin is a better approach since you don’t have to worry about theme updates or creating errors in your functions.php as you edit it.

So to create a plugin we create a new file and paste the following code:

 Ways to Add Google Analytics in WordPress

Install and activate the plugin so that you can start tracking your site using Google Analytics.

Conclusion

We have successfully outlined ways to add Google Analytics in WordPress. You can use each of these methods to add Google Analytics to WordPress. I recommend using plugin to add Google Analytics to WordPress since it is not only easy but very fast. I hope you find this article helpful, if you have additional questions, comments or compliments please leave a comment.