Google Analytics

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. Page Tracking

    Modify the default pages Google Analytics measures.

  3. Event Tracking

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

  4. Ecommerce Tracking

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

  5. Experiments

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

  6. Social Interaction

    Measure clicks and interactions with social buttons and plugins.

  7. User Timings

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

  8. Custom Dimensions & Metrics

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

  9. Domains & Cookies

    Understand the implications of multi-domain implementations.

  10. Google I/O 2013 video recap


  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.

  3. Google I/O 2014 Information

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.