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 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 Analytics, and click Admin. From the Account and Property columns, select the property you’re working with. Click Tracking Info / Tracking Code.
<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 this tracking code snippet on multiple domains.
- Copy the snippet.
Don’t edit your snippet. Just copy it. You might want to paste it into a text editor if you’re worried about accidentally losing or changing the snippet.
- Paste your snippet (unaltered, in it’s entirety) into every web page that you want to track. Paste it immediately before the closing
If your website uses templates to generate pages, enter it just before the closing tag in the file that contains the
- 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.
Customise your tracking code
After you complete the basic set up, you can customise your tracking code to collect data that isn't tracked automatically. We recommend setting up Event tracking, which lets you track rich media like videos, and Ecommerce tracking, which lets you integrate any product or sales data with your other data.
Set up cross domain tracking and more advanced options (for developers)
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 once the analytics.js library has loaded, and working with multiple tracking objects.
Visit 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.
For information on all other 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 configuration.
When you set up your property, you had an option to choose Universal Analytics or Classic Analytics. The tracking code snippet and the options that you get are different depending on which version you use. You can follow these set up instructions for both versions of the tracking code, but you cannot send data from a Universal Analytics tracking code to a Classic Analytics property. If you do so, your data will not be processed. If you use Classic Analytics, your advanced configurations options will be different and you will not get access to new features and future product updates. Learn more about Universal Analytics.