[UA] Set up the Analytics Google tag [Legacy]

You are viewing a legacy article about Universal Analytics. Learn more about Google Analytics 4 replacing Universal Analytics.

In this article:

Basic instructions

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

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

Find your Tracking ID and Google 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 Google tag is displayed farther down the page in a text box under Website Tracking > Google tag (gtag.js)

The Google tag

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

<!-- Google tag (gtag.js) -->

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

</script>

To add the Google tag to your webpages:

  1. Copy the entire contents of the text box.
  2. Paste it after the opening <head> tag on each page you want to measure.

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 Google tag into the source code on every webpage you want to measure.

  1. Find the Google tag for your property, and copy the code exactly without editing it.
  2. Paste your code (unaltered, in its entirety) after the opening <head> tag on each page 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 Google tag in the source code for every web page you want to measure. You can use a common include or template to push the Google tag dynamically into every web page.

  1. Find the Google tag for your property and copy the code exactly without editing it.
  2. Paste your Google tag into its own include file.
  3. Link the include file so that the snippet appears after the opening <head> tag on each page you want to measure.

If you’re using PHP:

  1. Find the Google tag for your property and copy the code exactly without editing it.
  2. Paste your Google 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 Google 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 Google tag installation by offering plug-ins that automatically install Analytics on your web pages.

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

Verify that your Google 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?
true
Choose your own learning path

Check out google.com/analytics/learn, a new resource to help you get the most out of Google Analytics 4. The new website includes videos, articles, and guided flows, and provides links to the Google Analytics Discord, Blog, YouTube channel, and GitHub repository.

Start learning today!

Search
Clear search
Close search
Main menu
3299890225062134495
true
Search Help Center
true
true
true
true
true
69256
true
false