Skip to main content

Using Autocapture

Sidecar automatically tracks various web activities, allowing you to create both simple and complex Metrics within Statsig console without writing a line of code. Create a new metric in the Metrics tab on the Statsig console to get started, and read more about the metrics we automatically log in Autocapture on the Web. See Autocapture on the Web

Using the tracking API

You can track events manually for actions that are not autocaptured by the feature described above. To track events back to Statsig, you can call StatsigSidecar.logEvent which takes the same arguments as the Statsig JS SDK as documented here. This method can be called prior to completion of the init routine.
// 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 gets invoked each time Sidecar activates an experiment assignment, including experiments activated later by prerun scripts. This method should be defined anywhere prior to the Sidecar client script.
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:
  • event.name - always "experiment_evaluation"
  • event.experiment - the full Statsig experiment object
  • event.experimentName - the Sidecar experiment name, or the Statsig experiment name as a fallback
  • event.groupName - the assigned group / variant, or null if unavailable

Post-Experiment Callback for one-time readiness hooks

You can still bind window.postExperimentCallback if you need a callback after Sidecar finishes its initial run. This callback can fire even when there are no experiments, and it does not cover experiments that are activated later by prerun scripts.
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 logging who has seen your experiments) append the following query string parameter to the Sidecar script URL: &autostart=0. This may be useful if you’re dealing with GDPR compliance, and you can later re-enable events with client.updateRuntimeOptions({disableLogging: false})