On this page

Measuring Experiments

Learn how to measure experiment results using autocapture, the manual tracking API, and Sidecar callbacks for analytics integrations.

Using Autocapture

Sidecar automatically tracks various web activities, letting you create simple and complex metrics in the Statsig console without writing code. Create a new metric in the Metrics tab on the Statsig console to get started. For a full list of automatically logged metrics, refer to Autocapture on the Web.

Using the tracking API

You can track events manually for actions Autocapture doesn't capture. To track events to Statsig, call StatsigSidecar.logEvent, which accepts the same arguments as the Statsig JS SDK, as Logging an event documents. You can call this method before the init routine completes.
js
// example order event
StatsigSidecar.logEvent('Order', null, {
  total: 54.66,
  units: 3,
  unitAvgCost: 18.22
});

Per-assignment callback for outbound integrations

You can bind a callback that Sidecar invokes each time it activates an experiment assignment, including experiments that prerun scripts activate later.

Define this method before the Sidecar client script.

js
window.statsigSidecarConfig = {
  onExperimentEvaluation: function (event) {
    /**
     * add your own callback routine here
     * ie; annotating 3rd party analytics tools with assignment info
     */
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      event: "statsig_experiment_evaluation",
      experiment_name: event.experimentName,
      experiment_group_name: event.groupName,
    });
  }
}

The callback payload includes the following fields:

Post-experiment callback for one-time readiness hooks

You can bind window.postExperimentCallback to receive a callback after Sidecar finishes its initial run. This callback fires even when there are no experiments, but doesn't cover experiments that prerun scripts activate later.

js
window.postExperimentCallback = function(statsigClient, experimentIds) {
  // One-time initialization hook after Sidecar finishes the initial run
}

Disabling all logging

To disable all logging to Statsig (both autocapture events and experiment exposure logging), append the following query string parameter to the Sidecar script URL: &autostart=0. Disabling logging is useful for GDPR compliance. You can re-enable events later with client.updateRuntimeOptions({disableLogging: false}).

Was this helpful?