Installation
Install Ours Privacy experimentation through the Web SDK, Tag Manager, or a manual script tag plus explicit init. Supports SPA frameworks including React, Vue, and Next.js.
Installation
The Ours Privacy experiment runtime is a small JavaScript file that evaluates experiments, assigns variants, and applies DOM modifications before the page fully renders.
If your website already runs the Ours Privacy Web SDK, you do not need to install a second script. Add your experimentation token to the existing ours('init', ...) call and publish.
Option 1: Ours Web SDK (Recommended)
If you are already using the Ours Privacy Web SDK, add your Experiment Token to the existing init options:
ours('init', 'YOUR_CDP_TOKEN', {
experimentation: {
token: 'YOUR_EXPERIMENT_TOKEN',
},
});This uses your current Web SDK install to load experimentation automatically. No extra script tag is required.
Under the hood, the Web SDK loads the experiments script and then calls window.ours_experiments.init({ visitorId }) with the shared CDP visitor ID. That keeps assignment, conversion tracking, and attribution aligned with the rest of the platform.
Option 2: Ours Tag Manager
If you are already using the Ours Privacy Tag Manager, add your Experiment Token to the Ours init tag configuration.
The tag manager will load the experiment runtime and initialize it with the shared visitor ID automatically. No separate script tag is required.
Option 3: Manual Script Tag
Only use this option if you are not already loading the Ours Web SDK or Ours Tag Manager.
Add the experiment script to the <head> of every page where you want experiments to run. Your token is shown on the experiment settings page in the dashboard.
CDN
<!-- Add to <head>, before other scripts -->
<script src="https://cdn.oursprivacy.com/experiment-init?token=YOUR_TOKEN" async></script>
<script>
window.addEventListener('load', function () {
window.ours_experiments.init({
visitorId: window.ours_data?.visitor_id,
});
});
</script>Custom Domain
If you have a custom domain configured (recommended), use it instead:
<!-- Add to <head>, before other scripts -->
<script src="https://YOUR_CUSTOM_DOMAIN/experiment-init?token=YOUR_TOKEN" async></script>
<script>
window.addEventListener('load', function () {
window.ours_experiments.init({
visitorId: window.ours_data?.visitor_id,
});
});
</script>Replace YOUR_TOKEN with the token shown on your experiment settings page, and YOUR_CUSTOM_DOMAIN with your configured custom domain.
Important: The experiments script no longer auto-starts. You must call
window.ours_experiments.init(...)after the script is available.
Identity note: Experimentation is designed to run with the Ours Web SDK or Tag Manager so the shared CDP visitor ID is passed into
init(). You can technically callinit()without a visitor ID, but the runtime will warn and generate a fallback ID, which limits analytics and attribution usefulness.
Redirect experiments
<!-- Synchronous — use on pages with redirect experiments -->
<script src="https://cdn.oursprivacy.com/experiment-init?token=YOUR_TOKEN"></script>
<script>
window.ours_experiments.init({
visitorId: window.ours_data?.visitor_id,
});
</script>SPA Frameworks (React, Vue, Next.js)
After window.ours_experiments.init(...) runs once, the runtime automatically handles SPA navigation. When the visitor navigates to a new route (via pushState or replaceState), the runtime re-evaluates URL targeting and applies any matching experiments.
No additional configuration is required for SPA support.
Next.js (App Router)
Add the script tag to your root layout:
// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<head>
<script src="https://cdn.oursprivacy.com/experiment-init?token=YOUR_TOKEN" />
<script
dangerouslySetInnerHTML={{
__html: `
window.addEventListener('load', function () {
window.ours_experiments.init({
visitorId: window.ours_data?.visitor_id,
});
});
`,
}}
/>
</head>
<body>{children}</body>
</html>
);
}Checking that the SDK is ready
The script exposes window.ours_experiments as soon as it loads, but assignments and visitor context are not ready until window.ours_experiments.init(...) runs. In framework code, call init() first, then check for assignments or subscribe to on('assigned', cb).
Verifying Installation
After the runtime loads and window.ours_experiments.init(...) has run, open your browser's developer console and run:
window.ours_experiments.getAssignments();
// { "exp-id-1": "variant-id-1", ... }If you see an empty object {}, either no active experiments target the current URL, or the visitor was not included in the traffic allocation. Check the experiment's targeting rules and traffic allocation percentage in the dashboard.
Next Steps
- JavaScript SDK: Programmatic API for reading assignments and tracking conversions
- Content A/B Tests: Guide to DOM modification experiments
- Redirect Tests: Guide to redirect experiments
- Personalization: Always-on audience targeting
How is this guide?