Varypilot/ DOCUMENTATION
Open app ↗

Integrations

Browser JavaScript SDK

Assign a variation, render the experience and record consented events.

Load the browser client

Use the project Integration section to copy a snippet with your actual key, environment and endpoint. Load the script before creating the client. Do not include a private server key in browser code.

Integration structure

Replace the uppercase identifiers and application callbacks below with values from your own project. They are integration placeholders, not production visitor data.

javascript
// Load https://app.varypilot.com/sdk/v1/browser.min.js first.
const ab = new Varypilot.BrowserClient({
  projectKey: PUBLIC_PROJECT_KEY,
  environment: ENVIRONMENT_NAME,
  endpoint: "https://varypilot-edge-api.silva-pires-ricardo86.workers.dev",
  visitorId: STABLE_PSEUDONYMOUS_VISITOR_ID,
  consent: false
});
await ab.init();
ab.setConsent(ANALYTICS_CONSENT_GRANTED);
const variant = ab.getVariant(EXPERIMENT_KEY, CONTROL_VARIANT_KEY);
renderAssignedExperience(variant);
ab.trackExposure(EXPERIMENT_KEY, variant);
// At the actual outcome:
ab.track(GOAL_EVENT_NAME, { eventId: STABLE_EVENT_ID });
await ab.flush();