How to Add Google Analytics to Your WordPress Website

It’s important to understand how your audience interacts with your website and the best way to do this is with Google Analytics.

Google Analytics not only lets you measures your sales and conversions, but also gives you insights into how visitors use your site, how they arrived on your site, and how you can keep them coming back.

In today’s Weekend WordPress Project we’ll explore why Google Analytics has become the industry for analysing website traffic, and how you can use it with your website.

Why You Should Use Google Analytics

Not only is Google Analytics a free tool, but it more importantly can help you keep track of some vital statistics.

Getting to Know Your Visitors

Google Analytics can help you analyze your visitor traffic, painting a picture of who your audience is and what they are looking for.

The Google Analytics website.
The Google Analytics website.

You can find out information such as their geographical location, which browser they are using, and even their screen resolution and language. Google Analytics can also tell you what time they landed on your site, how long they spent browsing, and the bounce rate (the percentage of visitors who left your site after their first visit). All of this information can help you better tailor the design of your website to improve the visitor experience.

For example, if your analytics data show more of your visitors are from China and are using mobile devices, you may want to add language support to your site and ensure it displays well on smaller screen.

If users are spending more time on your website in the morning, you may also want to switch up your posting schedule to take advantage of those early visitors.

Adding Google Analytics to Your Site

There are two main ways you can add Google Analytics to your site.

Getting Started

This tutorial assumes you already have a Google Analytics account. If you don’t, it only takes a second to sign up, especially if you already have an account with Google. Head to the Google Analytics site and create a new account.

After you’ve signed up, you’ll be given a piece of JavaScript code to add to your site.

Your Google Analytics account will provide you tracking code similar to this.
Your Google Analytics account will provide you tracking code similar to this.

Copy this tracking code and leave the page open in your browser in case you need to refer to it again. The next step involves adding this code to your site using one of the following two techniques:

Method 1: Editing Your header.php File

In the backend of your site, go to Appearances > Editor.

Open your theme’s header.php file and directly underneath the <body> tag, paste the tracking code. Click Update File.

Method: 2Editing Your functions.php File

Alternatively, you can add the following code to your theme’s functions.php file:

Don’t forget to paste in your analytics code.

Check Analytics is Working On Your Site

Once you’ve inserted the tracking code into your theme, your Google Analytics tracking status should change.

Go back to your Google Analytics account. Click on Admin at the top of the page and under Property choose your site and then click Tracking Info.

If the tracking status is “Receiving Data” then you’ve successfully added Google Analytics to your site.

You can now click on the Reporting tab at the top of the page to see your site’s analytics overview.

Note: It may take Google up to 12-24 hours to start providing you with site stats, so be patient and wait if your analytics don’t start updating right away.

Using a Google Analytics Plugin Instead

If you don’t want to edit your theme’s files, our Google Analytics + is the plugin can make the process all the more easier for you.

It puts all the important statistics at your fingertips by adding beautiful charts and graphs to your dashboard and the post edit screen.

You can view statistics for individual posts, a site or even an entire Multisite network. There’s also a one-click Google login process that allows easy access to your analytics. Just add a new account ID in the network settings to start collecting data for your entire multisite network.

How has Google Analytics helped you improve your website? Let us know in the comments below.