Set up the web tracking code

Follow these instructions to collect basic page tracking data from a website. Once you have successfully installed basic page tracking on your site, you'll see data in most of your Analytics reports, including traffic referral information, user characteristics and browsing information. It may take 24 hours for data to appear in your reports once tracking has been installed.

In this article:

Decide how to add tracking

There are two ways to collect page tracking data:

  • Add the Analytics tag (Universal Analytics) to your website container using Google Tag Manager. This approach is recommended because using Google Tag Manager simplifies tag management on your site. Using Google Tag Manager makes it easier to add other tags (such as AdWords Conversion Tracking and remarketing tags) to your site and configure your Analytics tracking.
  • Add the tracking code directly into the HTML of every page of your website. This is the easiest approach if you only want to add the basic Analytics tracking code to your site.
Not collecting data from a website? To collect data from a mobile app, use one of the Analytics SDKs. To collect data from an Internet connected device (a point-of-sale device, for example, but not a website or mobile app), use the Measurement Protocol.

Add tracking using Google Tag Manager

If you are unfamiliar with Google Tag Manager, begin by reading About Google Tag Manager. Once you're ready to set up a Google Tag Manager account and set up Google Tag Manager on your site, read Setup and Workflow (Web).

To add Analytics tracking to your site, add the Analytics tag to your container in Google Tag Manager and publish the container.

Add the tracking code directly to your site

To complete this process, you must have access to your website source code, be comfortable editing HTML (or have a webmaster/developer who can help you) and have an Analytics account and property already set up.

To set up the web tracking code:

  1. Find the tracking code snippet for your property.
    Sign in to your Analytics account, and select the Admin tab. From the ACCOUNT and PROPERTY columns, select the property that you’re working with. Click Tracking Info > Tracking Code. Image of where you find your tracking code in your Analytics account. Click to expand this image and see where these options appear in the interface.
  2. Find your tracking code snippet. It's in a box with several lines of JavaScript in it. Everything in this box is your tracking code snippet. It starts with <script> and ends with </script>.
    The tracking code contains a unique ID that corresponds to each Analytics property. Don’t mix up tracking code snippets from different properties and don’t reuse the same tracking code snippet on multiple domains.
  3. Copy the snippet.
    Don’t edit your snippet. Just copy it. You might want to paste it into a text document if you’re worried about accidentally losing or changing the snippet from your clipboard.
  4. Paste your snippet (unaltered, in its entirety) into every web page that you want to track. Paste it immediately before the closing </head> tag.
    If you use templates to dynamically generate pages for your site (like if you use PHP, ASP or a similar technology), you can paste the tracking code snippet into its own file, then include it in your page header.
  5. Check your setup.
    Make sure that the tracking snippet installed on your website matches the code shown in the view, and see more ways that you can verify your setup.

Related resources


Refer to Introduction to analytics.js to learn more about Analytics tracking code.


Refer to the Analytics (Universal Analytics) tag if you use Google Tag Manager to manage your Analytics tracking.

Was this helpful?
How can we improve it?

Need more help?

Sign in for additional support options to quickly solve your issue