Introduction to Analytics.js

The analytics.js JavaScript snippet is a new way to measure how users interact with your website. It is similar to the previous tracking code, ga.js, but offers more flexibility for developers to customize their implementations.

Tracking Code Quick Start

To begin tracking a website using analytics.js, paste the following JavaScript snippet into your website template page so that it appears before the closing </head> tag. The UA-XXXX-Y, parameter must be replaced with the Web Property ID for the Google Web Property you wish to track.

<!-- Google Analytics -->
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');

<!-- End Google Analytics -->

When the code runs, it asynchronously loads the Google Analytics Tracking Code onto the page. It then creates a tracker object for the web property you specified in the UA-XXXX-Y parameter. Finally, it records a pageview in Google Analytics for the page that the script was run.

What Next

  1. Advanced Configuration

    Customize your implementation using the rich set of anlaytics.js APIs.

  2. App / Screen Tracking

    Measure how users interact with your app.

  3. Cross Domain Tracking

    Measure users across domains.

  4. Display Features

    Enable features such as Remarketing, Demographics and Interest Reporting, and more.

  5. Custom Dimensions & Metrics

    Level up. Send custom business data directly to Google Analytics.

  6. Domains & Cookies

    Understand the implications of multi-domain implementations.

  7. Ecommerce Tracking

    Collect ecommerce data with Google Analytics to measure true return on investment.

  8. Event Tracking

    Go beyond pageviews. Measure how users interact with web content.

  9. Exception Tracking

    Measure the number and type of crashes and exceptions that occur in your app.

  10. Experiments

    Test changes to your property to see how they perform in optimizing for a specific goal.

  11. Page Tracking

    Modify the default pages Google Analytics measures.

  12. Social Interaction

    Measure clicks and interactions with social buttons and plugins.

  13. User ID

    Enable the analysis of groups of sessions, across devices.

  14. User Timings

    Measure the time it takes for resources to load with this generic time measurement.


  1. Method Reference

    Details of the objects and methods exposed by the analytics.js library.

  2. Field Reference

    The comprehensive list of all configuration fields for the analytics.js library.