Set up the Analytics global site tag

In this article:

Basic instructions

  1. If you have not already done so, create a Google Analytics property for each website you want to collect data from.

    Creating a property generates a unique Tracking ID and a global site tag that includes the Tracking ID for that property. See the following section for information about finding your Tracking ID and global site tag.
  2. Copy and paste the global site tag right after the opening <head> tag on each webpage you want to measure.

Find your Tracking ID and global site tag

  1. Sign in to your Analytics account.
  2. Click Admin.
  3. Select an account from the menu in the ACCOUNT column.
  4. Select a property from the menu in the PROPERTY column.
  5. Under PROPERTY, click Tracking Info > Tracking Code.

    Your Tracking ID is displayed at the top of the page.

    Your global site tag is displayed farther down the page in a text box under Website Tracking > Global Site Tag (gtrag.js)

The global site tag

The global site tag is several lines of code that you need to paste into each webpage you want to measure:

<!-- Global Site Tag (gtag.js) - Google Analytics -->

... (several lines of code) ...

</script>

To add the global site tag to your webpages:

  1. Copy the entire contents of the text box.
  2. Paste it immediately after the <head> tag on each page of your site.

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:

Static website

A static website does not generate HTML using a programming language or interface like Python or PHP. To collect data, you need to copy and paste the global site tag into the source code on every webpage you want to measure.

  1. Find the global site tag for your property, and copy the code exactly without editing it.
  2. Paste your code (unaltered, in its entirety) before the closing </head> tag on every webpage you want to measure.

Learn more about how to collect and send data from webpages to multiple Analytics properties.

Dynamic website

A dynamic website generates HTML using a programming language or interface like Python, PHP, etc. To collect data, include the global site tag in the source code for every webpage you want to measure. You can use a common include or template to push the global site tag dynamically into every webpage.

  1. Find the global site tag for your property, and copy the code exactly without editing it.
  2. Paste your global site tag into its own include file.
  3. Link the include file in your page header so that the snippet appears before the closing </head> tag on every webpage you want to measure.

If you’re using PHP:

  1. Find the global site tag for your property, and copy the code exactly without editing it.
  2. Paste your global site tag into a file named "analyticstracking.php".
  3. Include the analyticstracking.php file on each PHP template page.
  4. For each template page, immediately after the opening <body> tag, add the following code:
    <?php include_once("analyticstracking.php") ?>

Note that you can update the global site tag for dynamic websites more efficiently using Google Tag Manager.

Web-hosting service (you don't control the page code)

Some Internet service providers or hosting platforms (e.g., Wordpress, GoDaddy, Wix, Weebly) simplify global-site-tag installation by offering plug-ins that automatically install Analytics on your webpages.

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 global site tag, read the Google Tag Manager setup and installation guide.

Verify that your global site tag is working

To verify that the tag is working, visit your website, and then check the Real-Time reports in Analytics to verify that your visit was registered.

You can also use Google Tag Assistant to determine whether your tag is implemented correctly.

Download Tag Assistant | Learn more about using Tag Assistant

gtag.js Developer Guide

Was this helpful?
How can we improve it?