Best practices for implementing analytics.js on modern websites.
For an in-depth explanation of all the features used in this boilerplate (as well as how to report on them), see my article:
The base boilerplate extends the default tracking snippet and includes the following features:
- Tracks uncaught errors.
- Tracks custom user, session, and hit-level dimensions.
- Sends an initial pageview.
- Sends a pageload performance event.
The autotrack boilerplate builds on top the base boilerplate and includes select autotrack plugins
The multiple-trackers boilerplate builds on the autotrack boilerplate and includes support for using multiple trackers.
Running the boilerplate locally
To install the dependencies and load the boilerplate in a browser, run the following commands:
npm install npm start
Then visit localhost:8080 in your browser and open the developer console to see the analytics.js debug output.
Running different boilerplate versions
import('./analytics/base.js') with the version you want to load.