Google-Analytics-LogoWhat's the one thing you always do when you create a website? Add Google Analytics of course. The very reason for creating a Wordpress website in the first place is so that it generates web traffic so you should make sure that the site's traffic is being tracked by Google Analytics! If you've been around the web for a while, do you remember those Hit Counters which looked a little bit like this?

Hit Counter

Thankfully, those have been dead and buried a long time. Google Analytics provides any website owner with many tools to monitor their traffic, the best sources of their traffic, whether the website is achieving its goals (whatever those may be) and so many other handy tools necessary for the demands of today's website.

How do I add the Google Analytics code to my WordPress theme?

It's very easy to add Google Analytics to Wordpress - you should be able to do it correctly in less than a minute.

Step 1: Create a new property for your website in Google Analytics

This is fairly simple - sign up to Google Analytics and create a property for your website. You'll soon be given a code snippet (javascript) which you'll need to add to your WordPress theme. You can see an example of the code which is generated for inserting into your WordPress site below. Copy this code, you're going to need it in a minute.

Google-analytics-tracking-code

 

 

Step 2: Add your Google Analytics code to your WordPress theme

Now comes the fun part. You'll need to add the code to a specific file which is executed on each page, such that the Google Analytics code is added to each page on your Wordpress site. Luckily, a file which does exactly this already exists. It's called the header.php file and we're going to use it to insert our tracking code.

Log on to your Wordpress admin, and go to Appearance > Editor

Find the file called header.php. Google recommends that the tracking code goes immediately after the opening<body>tag, so find the <body> tag and in the next line, paste the code which you've copied from the .js Tracking Info page in Google Analytics and click on Update File to save your changes.

Wordpress-headerphp

Step 3: Confirm with Google Analytics that the code is sending data

Google Analytics Receiving Data

The final step is to confirm that everything is working ok. You can do this by Google back to Google Analytics, in the Tracking Info page. You should see that the Tracking Status has changed to "Receiving data". If it isn't, then you have done something wrong. You should first check that the code actually appears on your website by visiting your site and doing a "view-source" and searching for analytics.js to confirm that the code exists on the page. If it isn't you probably missed a step somewhere.

Step 4: Start analysing your website's traffic

The great thing about Google Analytics on a Wordpress website is that you don't have to even wait to start seeing what is happening on your site. Visit the Real-Time section of Google Analytics and you can immediately start monitoring your website's traffic.

Download the list of 101 WordPress tricks every blogger should know

101 WordPress tricks

Click here to Download Now

One more thing... Did you know that people who share useful stuff like this post look AWESOME too? ;-)
Please leave a useful comment with your thoughts, then share this on your Facebook group(s) who would find this useful and let's reap the benefits together. Thank you for sharing and being nice!

Featured On

Inc Magazine Logo  

Sitepoint logo  

CSS Tricks logo   

webdesignerdepot logo   WPMU DEV logo   

and many more!

Where are we hosted?

This site is proudly powered by FAST VPS InMotion Servers and given an insane speed thanks to MaxCDN!

Web Hosting MaxCDN - Speed up your website

New! DIVI 3.1 WordPress Template + PageBuilder

You'll surely create a perfect website with Divi 3.1!

Get an exclusive 10% OFF for CollectiveRay visitors until

Divi 3

 

WordPress Elementor Sale

Themes for the most popular WordPress page builder from TemplateMonster!

We've got an exclusive 10% OFF for CollectiveRay visitor until - use Coupon Code: collectiveray

TemplateMonster Elementor sale

 

TemplateMonster Bundles

Awesome bundles for awesome websites. $1300 worth of products for $49 only!

We've got an exclusive 10% OFF for CollectiveRay visitors until - use Coupon Code: collectiveray

TemplateMonster Bundles

How to make your website FAST!

Step-by-step - free email course, how to make your website load in less than 1 second 

The Outstanding HungryJPEG Bundles

AWESOMENESS! Bundles of premium font + graphic packs at more than 96% OFF!  Get a bundle for just $9 - ONLY!

The Hungry JPEG Awesome font bundles

 

Advertise on CollectiveRay.com

CollectiveRay (formerly known as DART Creations) is interested in developing partnerships with mutual benefit. If you like the stuff we publish and would like to develop a relationship, we'd be happy to hear from you. Go on - drop us a line - we'd love to hear from you :-)

 

 

Disclosure: CollectiveRay is funded personally out of pure passion for helping people working with websites. We do however generate some income through recommendations of products. This means if you click on a link and purchase an item we link to, we will receive a small sum out of that sale. We usually partner with vendors to make your purchase cheaper than buying direct.

who are we?

CollectiveRay is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites. We also run DronesBuy.net - a website for drone hobbyists.

David attard

Follow us on Social

Follow us on Facebook   Follow us on Google+   Subscribe to our RSS Feed   Follow us on Twitter