How to Set Up Google Analytics in WordPress

In online marketing, keeping track of your visitors and customers is key. There are a lot of premium programs which can keep track of a lot of metrics and data for a price. However, for the price conscious business, one of the best tools, Google Analytics, is free.

In this post, we will tell you how to setup Google Analytics for your WordPress website. First, you will need a Google Account. Then, head off to

After setting up a Google Account, if you don’t already have one, get into Google Analytics and choose website at the top. Google has 2 different tracking codes, Classic and Universal. It is recommended to choose the Universal code, as the Classic code is likely to be phased out by Google in the near future.

Below that, add an account name, website name, and website URL. Under one account name, you can track multiple properties, or websites.

Then we set the reporting time. This is the time that the reports will be generated to. You should use the time zone where your main target audience is located. For local businesses, this will be your time zone. If your business is international or global, you might want to set it to your target audience or geographical location.

If your business is not time sensitive, I would suggest using your time zone to make planning content a bit easier. Keep in mind that if you are targeting customers in another time zone, their mornings are not your mornings!

When you are all set up, click the blue button at the bottom which says “Get Tracking Code”. The next screen will be the Google ToS that we have to accept if we want to use Google Analytics.

After this step, you will get a code which is very long. If you get lost, you can navigate back to it via the sidebar on the left side of the screen. This is the code that you need to put into your WordPress Site to start tracking.

Go into your WordPress Dashboard, click on Themes – Editor to get to this screen.

Here we can access a lot of the code for your website. You wan to access the header.php and modify it. You should see lots of code! Don’t worry, we do not need to understand all of this. And your code might vary depending on what theme you are using.

Find the place where you see this:

<?php wp_head (); ?>

You want to copy the Google Analytics tracking code between these two lines!  

<?php wp_head (); ?>



Once that is done, click Save, and you are finished. Then, go back to Google Analytics, and wait 2-3 days for the first pieces of data of your traffic.

IMPORTANT: Using Google Analytics tracking requires further steps. Since the tracking works by installing cookies on visitors’ computers, it is important, for UX, SEO, and legal compliance depending on where your business is located, that you have a Privacy Policy on your webpage. This privacy policy should describe what information you collect, how you collect it, why you are collecting it, and what you want to use it for, as well as an option to opt out of it. Also, some jurisdictions require websites to disclose that they are using cookies. For example, if you are operating in the United Kingdom, you have to notify visitors that they are being tracked and give them the option to opt out as soon as they reach your page.