Are you interested in adding a Google Analytics tracking code to your website?
There are a few ways to add Google Analytics tracking code to your website. Adding Google Analytics to your website enables you to track the number of visitors to your site, the search keywords they use to find your site, the time spent on your site, goal conversion and much more.
We’ll explore two ways to add Google Analytics code to your website.
The first step you’ll 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:
- Log in to your Google Analytics account
- On the bottom left-hand side of the page, click Admin
- From the left column titled Account, select an account from the dropdown menu
- From the middle column titled Property, select a property from the dropdown menu
- Under the Property column, click Tracking Info > Tracking Code
- Your website’s unique tracking ID is shown at the top of the page under Tracking ID and starts with UA
Once you’ve identified your tracking ID, you’ll need to get your tracking code snippet, which can be found on this page as the Global Site Tag (
gtag.js is the tracking code for this specific property and you’ll need to copy and paste this code to every webpage you want to track on your website.
To copy and paste your
gtag.js, follow these steps:
- Copy the
gtag.jsshown on the page (example shown below)
- Replace the
GA_TRACKING_IDwith your unique tracking ID provided by Google Analytics
- Paste the code snippet right after the
<head>tag on each page of your site that you’d like to track in Google Analytics
Keep in mind that
gtag.js (launched in 2017) is a newer, more expanded version of analytics.js.
Google Tag Manager
You can also use Google Tag Manager to add the 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 from multiple campaigns.
To install Google Analytics code via Google Tag Manager (GTM), follow these steps:
- In GTM, select Create Tag and choose Google Analytics
- Then select Universal Analytics
- Name your tag, preferably something related to Google Analytics (like GA). Add your Google Analytics property ID or gaProperty variable.
- Choose the Track Type (i.e. Page View)
- Choose your firing triggers such as All Pages, which the tag will fire the tracker on every page of your website.
Gtag.js or Google Tag Manager?
If your website is already using Google Tag Manager, then
gtag.js is not necessary and continue to use 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 are not planning on investing in Google Adwords, using the
gtag.js may be beneficial to your website. The
gtag.js tag makes the tracking process easier by:
- Streamlining the installation process to get Google Analytics code on your site faster
- Allowing you to send event data to multiple tools as once
- Keeping all tracking tags in once place in your website code
Either way, we recommend that you add Google Analytics to your website, so you can keep track of all your event data.