[UA] Set up Analytics measurement with analytics.js

Tag your site for Google Analytics using analytics.js
In this article:

Basic instructions

The first step to setting up tracking for a website is to create an Analytics property. Create one Analytics property for each website you want to track.

Creating an Analytics property generates an ID and a JavaScript tag. The next step to set up tracking for a website is to do one of the following:

  • Add the entire tag to each web page you want to track. Add the tag right after the opening <head> tag on each page.

  • Enter the ID into a field that asks for the Google Analytics ID. (For some web-hosting services, you don't need to add the entire tag to each web page on your site. Instead, you'll simply need to enter the ID into a field. If this field exists, you can usually find it in the "Admin" or "Analytics" section of your web hosting. For more information, read "Web-hosting service", under Find the setup type, below.)

Find your tracking ID and tag

To find the tracking ID and code snippet:

  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.

Find the setup type

There are several ways to collect data from online properties in Analytics, depending on whether you want to track a website, an app, or some type of Internet-connected device. The following methods explain how to set up the tag for different types of properties.

  • Static website

    A static website is based on HTML that doesn't change dynamically, and is NOT generated using a programming language like Python, Ruby, or PHP.

    1. Find the Javascript tracking-code snippet for your property, and then copy the entire snippet. Don't make any changes to the snippet.
    2. Paste the entire snippet into the HTML on your web pages, right after the opening <head> HTML tag.

    If you want to send data from a single page to multiple properties, you can track a page using multiple accounts or multiple properties within a single account.

  • Dynamic website

    A dynamic website is one for which the HTML is generated using a programming language like Python, Ruby, or PHP. You can use an include statement or template to push the tag dynamically to each page.

    1. Find the Javascript tracking-code snippet for your property, and then copy the entire snippet. Don't make any changes to the snippet.
    2. Paste the entire snippet into its own include file, then add the include statement to your page header so that the snippet appears right after the opening <head> HTML tag.

    Using PHP?

    Copy the Javascript tag and add it to a file named analytics.php. Then include the analytics.php file on each PHP template page. For each template page, immediately after the opening <head> tag, add the following code:

    <?php include_once("analytics.php") ?>

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

  • Web-hosting service (you don’t manage the source code)

    Some Internet service providers or hosting platforms (such as Wordpress, GoDaddy, Wix, Weebly, etc.) simplify Analytics tracking-code installation by offering plug-ins that automatically install it on your web pages. Review your platform’s instructions to add your Analytics ID.

    Here are the Analytics implementation instructions for some common providers:

    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 track. If you have special requirements for tracking data, review how to get started with Analytics.

  • Website using Google Tag Manager

    Google Tag Manager is a free tool you can use to manage multiple analytics and site-tracking tags. To use Google Tag Manager to install your Analytics tag, read the Google Tag Manager setup and installation article.

  • Mobile app
  • Internet-connected device or CRM system

    To collect data from an Internet-connected device such as online point-of-sales system or video-game console, or from a CRM system or other platform, you need to use the Analytics Measurement Protocol.

Verify that your tag is working

Once you have successfully installed the Analytics tag, it can take up to 24 hours for data such as traffic-referral information, user characteristics, and browsing information to appear in your reports. However, you can check your web-tracking setup immediately.

Troubleshoot your tag setup

If you're not seeing any data, or not seeing the data you expect, you can use the troubleshooter to identify and resolve problems.

The Google Developers site is a great resource to learn more about how the tag works.

Was this helpful?

How can we improve it?
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!

Clear search
Close search
Google apps
Main menu