Set up (web)

Set up the web tracking code

Follow these instructions to use Google Analytics to collect data from websites.

To complete this process, you must have access to your website source code, be relatively comfortable with HTML (or have a developer that can help you), and already have a Google Analytics account and property set up. Learn more about properties and how to set up a property.

If you want to collect data from a mobile app, use one of the Google Analytics SDKs. For other digital devices, use the Measurement Protocol.

To set up the web tracking code:

  1. Find the tracking code snippet for your property.
    Sign in to your Google Analytics account, and click Admin in the top menu bar. From the Account and Property columns, select the property 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 Google Analytics property. Don’t mix up tracking code snippets from different properties, and don’t reuse the same tracking code snippet on multiple domains. This is your tracking code. Copy it from this box, and paste it in all of your webpages before the closing <head> tag. Click to expand this image and see where the tracking code snippet is in the interface.
  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 it’s entirety) into every web page 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 set up.
    Make sure that the tracking snippet installed on your website matches the code shown in the view, and see more ways you can verify your set up.

Next Steps

Set up and customize reporting views

A view is the lens through which you see your data. It’s the part of a Google Analytics account that has reports and tools you can use to analyze data.

Learn more about views, how to create a view, and why you should create a copy of your original view.

Add more tracking features

After you finish your set up, you can customize your tracking code to collect data that isn't automatically tracked by Google Analytics. We recommend setting up Event tracking, which lets you track how users interact with content like videos, buttons, downloads, outbound links, and other interactive elements. If you sell anything, we also recommend you set up Ecommerce tracking to integrate product and sales data with the other data you collect using Google Analytics.

Set up cross domain tracking (if necessary)

If you have multiple top-level domains and you want to see data from them in one Google Analytics property, you need to set up cross domain tracking. For example, if you have and, and you want to combine data from both domains into the same Google Analytics reports, you need to set up cross domain tracking. Learn more about cross domain tracking, or refer to our Developer Guide on cross domain tracking for analytics.js. When you set up cross domain tracking, include the additional domains in the referral exclusions list to avoid self-referrals in your reports.

Advanced tracking options

Developers can also configure advanced collection options, including overriding multiple values sent as a pageview, setting a parameter value to persist across multiple send commands, executing code only after the analytics.js library has loaded, and working with multiple tracking objects.

For information on all of the advanced configuration options, visit our Developer Guide on Advanced Configurations for analytics.js.

If you're using Classic Analytics, refer to the Developer Guide for ga.js when setting up an advanced configurations, including cross-domain tracking.

The changes you need to make depend on which tracking code you’re using. See if you have Classic Analytics (ga.js) or Universal Analytics (analytics.js).