- If you have not already done so, create a property in Google Analytics. Create one Analytics property for each website you want to collect data for. Creating a property generates a Google Analytics ID, which you'll use in your gtag.js installation.
- Find your Google Analytics ID, as described below. You'll use this Google Analytics ID in your setup.
- Copy and paste the global site tag to each web page you want to measure. Add the tag right after the opening
<head>tag on each page.
Find your Google Analytics ID
To find the Google Analytics ID:
- Sign in to your Analytics account.
- Click Admin.
- Select an account from the menu in the ACCOUNT column.
- Select a property from the menu in the PROPERTY column.
- Under PROPERTY, click Tracking Info > Tracking Code. Your Tracking ID is displayed at the top of the page.
The Global Site Tag
The global site tag is several lines of programming code that you'll need to paste on to each page of your site. Your customized global site tag appears in a text box under the heading "Global Site Tag (gtag.js)".
- Copy the entire contents of the text box.
- Paste it immediately after the
<head>tag on each page of your site.
<!-- Global Site Tag (gtag.js) - Google Analytics -->
... (several lines of customized programming code appear here)
Set up data collection based on your type of site
The method of collecting data in Analytics varies depending on the type of website you use:
A static website does not generate HTML using a programming language or interface like Python or PHP. To collect data, you copy and paste the Analytics tracking-code snippet in the source code on every web page you want to measure.
- Paste your snippet (unaltered, in its entirety) before the closing </head> tag on every web page on your site you want to measure.
A dynamic website generates HTML using a programming language or interface like Python, PHP, etc. To collect data, include the Analytics tracking-code snippet in the source code on every web page you want to track. You can use a common include or template to push the tracking code dynamically into every web page you want to measure.
- Paste your tracking-code snippet into its own include file. Then link the include file in your page header so that the snippet appears before the closing </head> tag on every web page on your site you want to measure.
If you’re using PHP:
- For each template page, immediately after the opening <body> tag, add the following code:
<?php include_once("analyticstracking.php") ?&tg;
Note that you can update the tracking code for dynamic websites more efficiently using Google Tag Manager.
Site on a web-hosting service (you don't control the page code
Some Internet service providers or hosting platforms (e.g., Wordpress, GoDaddy, Wix, Weebly) simplify Analytics tracking-code installation by offering plug-ins that automatically install Analytics on your web pages.
Here are Analytics-implementation instructions for some common providers:
Note that when you use a plug-in to collect data, you may not have the option of adding configuration settings to customize the data you want to measure. If you have special requirements for measuring data, review how to get started with Analytics.
Website using Google Tag Manager
Google Tag Manager is a free tool to help add and manage multiple analytics and site tracking tags. To use Google Tag Manager to install your Analytics tracking code, read the Google Tag Manager setup and installation guide.
Verify that the tag is working
To verify that the tag is working, visit your website and check to see that your visit is being registered in the Real-Time reports.
You can also use Google Tag Assistant to determine whether your tag is implemented correctly.