Analytics.js 2.0 (Beta)
Analytics.js 2.0 is recommended for use in staging
Analytics.js 2.0 was built with backwards compatibility in mind. However, Segment recommends thorough testing in a Staging environment before you upgrade your production source.
Analytics.js is Segment’s most popular library source. This new major version has been re-engineered to be more performant and provide greater extensibility. It is fully backwards compatible with the previous version of Analytics.js.
Benefits of Analytics.js 2.0
The Analytics.js 2.0 Beta provides two key benefits over the previous version.
Analytics.js 2.0 provides a reduction in page load time, which improves overall site performance. Its package size is ~70% smaller than the previous Analytics.js.
There are many factors that impact page load time, including page weight, network conditions, and hosting locations.
Analytics.js 2.0 introduces new ways for developers to augment events throughout the event timeline. This enables teams to support:
- New privacy and consent controls before an event occurs
- Enriching events with additional customer or page context in-flight using middleware
- Collecting better metrics related to deliverability after a message is sent
Start using Analytics.js 2.0
Analytics.js is released as a Public Beta, on an opt-in basis, per source. The updated code is delivered through your existing snippet, so there’s no need to update code on your site.
To opt in:
- Enable the Analytics 2.0 toggle.
Once enabled, after 5 minutes or less, the updated code is delivered.
Disable Analytics.js 2.0
To revert back to the previous version of Analytics.js, disable the Analytics 2.0 toggle on any source you’ve enabled it.
Cases that require manual upgrade
There are two cases where upgrading to Analytics.js 2.0 requires manual effort beyond enabling the Analytics.js 2.0 toggle.
When using in-domain instrumentation CDN aliasing
If the source you intend to upgrade uses the in-domain instrumentation as well as a custom “Alias for analytics.js”, then you should update the AJS snippet to the latest version (4.13.2 or higher) before you toggle on Analytics.js 2.0.
When using a strict content security policy on the page
Open source libraries
Analytics.js 2.0 includes the following open source components:
uuid v2.0.0 (https://github.com/lukeed/uuid) Copyright Luke Edwards <email@example.com> (lukeed.com) License: MIT License, available here: https://github.com/lukeed/uuid/blob/master/license
component-url v0.2.1 (https://github.com/component/url) Copyright (c) 2014 Component License: MIT License, available here: https://github.com/component/url/blob/master/Readme.md
dset v2.0.1 (https://github.com/lukeed/dset) Copyright (c) Luke Edwards <firstname.lastname@example.org> (lukeed.com) License: MIT License, available here: https://github.com/lukeed/dset/blob/master/license
js-cookie v2.2.1 Copyright (c) 2018 Copyright 2018 Klaus Hartl, Fagner Brack, GitHub Contributors License: MIT License, available here: https://github.com/js-cookie/js-cookie/blob/master/LICENSE
md5 v2.3.0 (https://github.com/pvorb/node-md5) Copyright (c) 2011-2012, Paul Vorbach. Copyright (c) 2009, Jeff Mott. License: BSD-3-Clause “New” or “Revised” License, available at: https://github.com/pvorb/node-md5/blob/master/LICENSE
unfetch v4.1.0 (https://github.com/developit/unfetch) Copyright (c) 2017 Jason Miller License: MIT License, available at: https://github.com/developit/unfetch/blob/master/LICENSE.md
This page was last modified: 10 Mar 2021
Questions? Problems? Need more info? Contact us, and we can help!