Google Analytics Code

 How to add Google Analytics tracking to a website

There are a few ways to add the Google Analytics tracking code to your website. Adding Google Analytics to your website allows you to track the number of visitors to your site, the search keywords they use to find your site, time spent on your site, conversion goals, and much more.

A few cleanup items before moving on, this tutorial assumes that you already have a standard Google Analytics account and not a Google Analytics 360 account. Second, that you have already set up a property in Google Analytics, which allows you to generate an ID follow-up (more on this later).

With that settled, we'll explore two ways to add Google Analytics code to your website.

Google Analytics tracking code

The first step you will need to do is find your Tracking ID, which is a unique ID created for your Google Analytics account.

To get your tracking ID, follow these steps:

Login to your Google Analytics account

At the bottom left of the page, click Administrator.

In the left column titled Account, select an account from the drop-down menu

In the middle column titled Property, select a property from the drop-down menu

In the Property column, click Tracking Information> Tracking Code

Your website's unique tracking ID is displayed at the top of the page below the tracking ID and begins with UA

Once you've identified your tracking ID, you'll need to obtain your tracking code snippet, which can be found on this page as Global Site Tag (gtag.js). Gtag.js is the tracking code for this specific property and you will need to copy and paste this code on each web page that you want to track on your website.

To copy and paste your gtag.js, follow these steps:

Copy the gtag.js shown on the page (example shown below)

google-analytics-code _global-site-tag

Replace GA_TRACKING_ID with your unique tracking ID provided by Google Analytics.
Paste the code snippet just after the <head> tag on each page of your site that you want to track in Google Analytics.
Note that gtag.js (released in 2017) is a newer and expanded version of analytics.js.

Google Tag Manager

You can also use Google Tag Manager to add Google Analytics code to your website. Google Tag Manager is a free tool and is useful for websites that use multiple analytics or advertising performance tools for multiple campaigns.

To install the Google Analytics code through Google Tag Manager (GTM), follow these steps:


(Source: Google Analytics documentation)

In GTM, select Create tag and choose Google Analytics

Then select Universal Analytics
Give your tag a name, preferably something Google Analytics related (like GA). Add your Google Analytics Property ID or the gaProperty variable.
Choose the track type (i.e. page view)
Choose your trigger triggers such as All Pages which tag will trigger the crawler on every page of your website.

Gtag.js or Google Tag Manager?

If your website already uses Google Tag Manager then gtag.js is not necessary and continue using GTM. Since GTM inherently combines event data from Google Analytics and Google Adwords, it's best to keep it running if it's already in place.

However, if you haven't installed GTM and you don't plan to invest in Google Adwords, using gtag.js can be beneficial for your website. The gtag.js tag makes the tracking process easy by:

Optimizing the installation process to get the Google Analytics code on your site faster
Allowing you to send event data to multiple tools as one time
Keep all tracking tags in one place in your website code
Either way, we recommend that you add Google Analytics to your website, so that you can keep track of all your event data.

Post a Comment

Previous Post Next Post