On this page

Advanced Configurations

Configure advanced Statsig Sidecar v3 settings, including custom triggers, multi-page tests, and integrations with analytics tools and consent providers.

Runtime settings for SPAs and manual activation

Visual Editor v3 includes runtime settings that let you control when an experiment starts running on the page. Configure these settings on the experiment setup page in the Statsig Console.

  • Disable Auto Run prevents Sidecar from automatically attempting to run the experiment on page load.
  • Custom activation lets you start the experiment manually with StatsigSidecar.activateExperiment("experiment_name").
  • Prerun Script lets you define a custom script that runs once before the experiment starts when the targeting rules pass. Use this to bind listeners or evaluate custom logic before manually activating the experiment.

Prerun Script is in beta. Reach out to Statsig Support to enable access for your account.

Advanced targeting and segmentation

This section describes how to set user identity and attributes for Sidecar to enable more advanced targeting and results segmentation.

By default, Sidecar and Autocapture use stableID (an auto-generated device-level GUID stored in the user's localStorage) for tracking. To enrich autocapture events with known user identities and attributes, define the following object before autocapture or Sidecar loads.

Watch this video tutorial on how to configure more advanced targeting for your Sidecar experiments.
js
window.statsigUser = {
  userID: "<USER ID>",
  custom: { // optional attributes object
     isLoggedIn: false 
  }
}

Accessing the Statsig JS client

To access the underlying Statsig js client instance, call StatsigSidecar.getStatsigInstance().

Configuring runtime options

Use runtime options to handle consent management, GDPR compliance, and more. All StatsigOptions provided by the JavaScript SDK are fully supported with Sidecar. Pass them to Sidecar using:
js
window.statsigOptions = {
  // example of disabling logging for 
  loggingEnabled: 'disabled'
}

Before the Sidecar script tag, configure these runtime options to disable browser storage and tracking:

js
window.statsigOptions = {
  loggingEnabled: "disabled",
  disableStorage: true
}

After the user gives consent, re-enable storage and tracking:

js
__STATSIG__.instance().updateRuntimeOptions({loggingEnabled: "browser-only", disableStorage: false});

Persisting stableID across subdomains

Statsig uses localStorage as the preferred mechanism for storing the user's stableID. localStorage keys don't persist across origin boundaries, including subdomains. For example, a user visiting https://example.com, https://show.example.com, and https://account.example.com receives three distinct stableIDs.

If you assign a user to a test on one subdomain and track behavior for metrics on a different subdomain, add the following solution to ensure Statsig correctly attributes cross-origin behavior to the Test Group assignment from the initial experiment domain.

Paste the following in your HEAD section.

html
<!-- cross domain id script -->
<script>!function(){let t="STATSIG_LOCAL_STORAGE_STABLE_ID";function e(){if(crypto&&crypto.randomUUID)return crypto.randomUUID();let t=()=>Math.floor(65536*Math.random()).toString(16).padStart(4,"0");return`$\{t()\}${t()}-$\{t()\}-4${t().substring(1)}-$\{t()\}-${t()}$\{t()\}${t()}`}let i=null,n=localStorage.getItem(t)||null;if(document.cookie.match(/statsiguuid=([\w-]+);?/)&&([,i]=document.cookie.match(/statsiguuid=([\w-]+);?/)),i&&n&&i===n);else if(i&&n&&i!==n)localStorage.setItem(t,i);else if(i&&!n)localStorage.setItem(t,i);else{let o=e();localStorage.setItem(t,o),function t(i){let n=new Date;n.setMonth(n.getMonth()+12);let o=window.location.host.split(".");o.length>2&&o.shift();let s=`.$\{o.join(".")\}`;document.cookie=`statsiguuid=${i||e()};Expires=$\{n\};Domain=${s};Path=/`}(o)}}();</script>

<!-- Manually attach stableID from local storage -->
<script>
if(localStorage.getItem('STATSIG_LOCAL_STORAGE_STABLE_ID')) {
  window.statsigUser = {
    customIDs: {stableID: localStorage.getItem('STATSIG_LOCAL_STORAGE_STABLE_ID')}
  }
}
</script>

<!-- sidecar script below -->
<script src="https://cdn.jsdelivr.net/npm/statsig-sidecar/dist/index.min.js?apikey=[client-YOUR-STATSIG-CLIENT-KEY]"></script>

Was this helpful?