Home

Web analytics and tracking for LogRocket websites

Marketing and analytics code used on LogRocket-related websites including the dasbhoard, main site, blog and podcast site.

Usage

The main purpose of this code is to package all the analytics script snippets (e.g. vwo, reddit, 6sense) into one function call: window.lr_analytics.init.

Other utility functions like window.lr_analytics.track and window.lr_analytics.identify are also provided.

Basic usage:

<!-- Use a script tag to load the code -->
<script src="https://storage.googleapis.com/lr-marketing-js/lr-web-analytics/script/3.js"></script>
<script>
  // In a second script tag, call `.init()` with an options object
  window.lr_analytics.init({
    segment: {
      enabled: true,
      writeKey: 'xyz',
      load: true,
    },
  });
  // Since we enabled `segment` in our `.init()` call
  // it should now be available.
  window.analytics.page();
</script>

Development

[!NOTE] Part of the functionality this package provides is the client-side "relay" or "analytics proxy" code. This code must be executed before any other http requests are made so that third-party analytics code is correctly proxied (e.g. segment). For this reason, this package is bundled as an iife so that it can be consumed as a non-module <script> tag which is synchronous (and blocks the main thread).

To run tests:

$ npm run test

[!NOTE] Each test file runs within its own isolated context.

To run tests using a non-headless browser you can try

$ npm run test-debug

To open up the examples in a browser:

$ npm run examples

To format and fix linting errors:

$ npm run check:fix

To publish a new version:

  1. Update the version in package.json and push that change to main if it has not yet been done.
  2. Run: gcloud auth application-default login
  3. Run node scripts/publish.mjs