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.
To set up the web tracking code:
- 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. Click to expand this image and see where these options appear in the interface.
<script>and ends with
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. Click to expand this image and see where the tracking code snippet is in the interface.
- 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.
- Paste your snippet (unaltered, in it’s entirety) into every web page you want to track. Paste it immediately before the closing
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.
- 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.
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.
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 example-1.com and www.example-2.com, 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.