Google Analytics Basics: How to Set it up Properly

Google Analytics is the most well-known analytics program for digital marketing. The best part? It is absolutely FREE!

Digital marketing without using analytics is like driving a car in the night without any lights and your dashboard is not working. You do not know where you are going. You do not know how fast you are going. You do not know if you are heading in the right direction or not.

It is not any better than traditional marketing. Think of billboard ads and tv commercials. You invest a lot in producing them in terms of money and time. Then, you do not have a direct way of measuring their impact to your business.

It does not have to be that way. Google Analytics is fairly simple to setup (and use for that matter).

[convertkit form=1458514]

There are three phases in setting up Google Analytics properly. Each phase is also broken into two parts.

How to Setup Google Analytics

Setting up Google Analytics can be divided into three (3) phases:

  1. Creation of the necessary accounts
  2. Installing the code to your website
  3. Checking (and troubleshooting, if necessary) the data

Phase 1: Creation of Accounts

Creating the necessary accounts is the first step.

You will need to create (or login to) a Gmail account. From there, head on over to the Google Analytics (GA) and Google Tag Manager (GTM) websites.

You need both GA and GTM accounts because the former allows you to analyze your website while the latter allows you to make changes to your website without having to learn code; thus, future-proofing your website.

Step 1: Create a Google Analytics Account

  1. Go to analytics.google.com
  2. Login to your Gmail account
  3. Sign up for a Google Analytics account
  4. Choose Website
  5. Input Basic Information About Your Company and Website
  6. Scroll Down and Get Tracking ID
  7. Accept Terms of Service
  8. Take note of your Tracking ID.

Step 2: Create a Google Tag Manager Account

  1. Go to tagmanager.google.com
  2. Login to your Gmail account
  3. Enter your company name (account)
  4. Enter your website’s domain (container)
  5. Choose Web
  6. Accept Terms of Service
  7. Copy the two sets of code given

Phase 2: Installing the Code

Before editing or making any changes — whether that’s adding or updating a plugin, or editing the code directly— it’s best practice to create a backup of your website first.

Installing the code involves two parts as well.

First, you setup Google Analytics inside Google Tag Manager. Next, you install the GTM code on your website.

Again, the primary reason why you should setup your analytics this way is because GTM allows you to change settings or add other code in your website without having to tinker with code. You just install the GTM code and add/edit/delete codes inside GTM. To learn more about how you can do this, check out my article on Google Tag Manager.

Step 1: Install Google Analytics code in Google Tag Manager

  1. Get your Google Analytics Tracking ID
  2. Login to Google Tag Manager
  3. Choose the container name you just created
  4. Add a new tag
  5. Name the tag as “GA Pageview”
  6. Choose Google Analytics
  7. Choose Universal Analytics as a tag type
  8. Create a new variable
  9. Name the variable as “gaProperty”
  10. Choose constant
  11. Enter your GA Tracking ID (Phase 1, Step 1)
  12. Click continue
  13. Choose to fire tag on “All Pages”
  14. Create Tag

Step 2: Install the Google Tag Manager code on your WordPress website

This part assumes you are using a WordPress-hosted website. Earlier, there are two sets of code you have to install.

I have provided here two separate options for you to take:

Option 1: Install via header.php file
  1. Login to Google Tag Manager
  2. Choose the container name you want to use
  3. Go to Admin
  4. Choose Install Google Tag Manager
  5. Copy the code
  6. Login your WordPress dashboard
  7. Go to Appearance, then Editor
  8. Search for the header.php file
  9. Paste the code immediately after the opening body tag
  10. Update the File
Option 2: Install via the functions.php file (Genesis Framework)

Before editing or making any changes — whether that’s adding or updating a plugin, or editing the code directly— it’s best practice to create a backup of your website first.

This second option is what I recommend, especially if you are using the Genesis Framework.

  1. Go to your theme’s editor and add it to the functions.php file.
  2. Login to your WordPress account.
  3. Go to Appearance > Editor.
  4. At the right-hand portion, click on the functions.php.
  5. Scroll down until you see the end of the lines of code there. Remember to not touch anything else. A single mistake there can break your entire site.
  6. Add your code
  7. Hit save

Copy this entire code and paste it there, then replace the GTM-ABCDEF section with your own container ID.

// Add Google Tag Manager code in <head>
add_action( 'wp_head', 'google_tag_manager_head' );
function google_tag_manager_head() { ?>
	
//Replace this entire line with the first part of the code <head>

<?php }


// Add Google Tag Manager code immediately below opening <body> tag
add_action( 'genesis_before', 'google_tag_manager_body' );
function google_tag_manager_body() { ?>
	
//Replace this entire line with the second part of the code <body>

<?php }

You’ll then have something that looks like this…

// Add Google Tag Manager code in <head>
add_action( 'wp_head', 'google_tag_manager_head' );
function google_tag_manager_head() { ?>
	
    <! – Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABCDEF');</script>
<! – End Google Tag Manager -->

<?php }


// Add Google Tag Manager code immediately below opening <body> tag
add_action( 'genesis_before', 'google_tag_manager_body' );
function google_tag_manager_body() { ?>
	
<! – Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-ABCDEF"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<! – End Google Tag Manager (noscript) -->

<?php }

Phase 3: Checking the Data

Just like the rest of this post, this is divided into two parts as well:

  1. Click on preview inside Google Tag Manager.
  2. Check real-time data in Google Analytics
  3. If it’s working, then hit publish

Step 1: Preview Your Container in GTM

  1. Go to your GTM account
  2. Click on preview at the top-right portion. The page will reload.
  3. Open a new tab and open your website.
  4. You should see the “tags” firing at the bottom of the screen
  5. If the tag is present, it’s working properly.
Google Tag Manager - Preview Tags Firing on Your Website

Step 2: Look at Real-Time Data in GA

  1. Go to your Google Analytics account
  2. Make sure you are in the Reports tab
  3. Click Real-Time
  4. Click Overview
  5. Open another tab in your browser and load any page on your website
  6. Go back to GA to see if it is working
    1. If it’s working, go back to GTM and click on “leave preview mode”
    2. If it’s not, it’s either you configured it wrong, or a plugin is preventing it from loading. Usually, ad blockers from your browser are the culprit.
Google Analytics Real-Time

Step 3: Publish Your Container

After verifying the data is coming in correctly, head back to Google Tag Manager and click on the submit button at the right-hand side.

You’ll be asked a few details to help you remember the changes you did. Once you’re done, click on Publish.

And that’s it.

You have now installed Google Analytics properly on your website using Google Tag Manager. Again, this is the ideal setup for adding code and apps to your website. That way, you don’t have to go through this setup again.

The next time you want to add code to your website, like the Facebook Pixel or your email marketing tracking code, or an A/B optimization software, you only have to add it via Google Tag Manager.

Ariel Lim

Ariel Lim

Management consultant / MBA / Inbound marketer who helps startups generate leads, create and execute strategies.

Leave a Comment

Ready to grow your organic traffic?

Enter your email and I’ll send you the case study of how I grew my organic traffic by 110% in just 3 months!