A dual-mode browser SDK for visual DOM element selection and live A/B testing experiments.
Optivise SDK operates in two modes:
Editor Mode - Visual element selection for dashboard integration. Hover and click elements to capture CSS selectors, HTML, and positioning data via postMessage - perfect for building experiment creation workflows.
Visitor Mode - Live A/B testing with Statsig integration. Automatically fetches and applies DOM patches based on experiment variant assignments from Statsig.
- 🎯 Visual DOM Selection - Hover and click to select elements
- 📍 CSS Selector Generation - Automatic selector generation
- 📊 Element Data Export - HTML, selectors, and bounding boxes via postMessage
- 🖥️ Dashboard Integration - Seamless communication with parent dashboard
- 🧪 Statsig Integration - Native support for Statsig experiments
- 🔄 Automatic Patching - Fetches and applies DOM changes based on variants
- 👤 User Targeting - Supports both identified and anonymous users
- 🎨 Dynamic Content - Changes content without code deployments
- 🚀 Easy Integration - One script tag, dual functionality
- 📦 Bundle Size - ~23KB gzipped (includes Statsig SDK)
For visual element selection in your dashboard:
<script
src="https://optivisesdk.pages.dev/optivise.js"
data-project="YOUR_PROJECT_ID"
async>
</script>Load your website in an iframe with ?optivise_edit=true:
https://yoursite.com/?optivise_edit=true
The SDK will send element data via postMessage when users hover/click elements.
For running live experiments with Statsig:
<script>
window.OptiviseConfig = {
projectId: 'your-project-id', // Optional, not used for patch fetching
statsigClientKey: 'client-YOUR_STATSIG_KEY', // Required
experimentKey: 'optv_homepage_test_1234567890', // Required - must match statsigExperimentKey from Optivise
userID: 'user-123', // Optional
debug: false // optional
};
</script>
<script
src="https://optivisesdk.pages.dev/optivise.js"
async>
</script>The SDK will:
- Initialize Statsig with your client key
- Retrieve the variant assignment
- Fetch the corresponding DOM patch from your API
- Apply the patch automatically
<!DOCTYPE html>
<html>
<head>
<title>Your Website</title>
</head>
<body>
<div id="hero">
<h1>Welcome to Our Site</h1>
<button class="cta">Get Started</button>
</div>
<!-- Add Optivise SDK -->
<script
src="https://optivisesdk.pages.dev/optivise.js"
data-project="my-project">
</script>
</body>
</html>window.addEventListener('message', (event) => {
if (event.data.type === 'optivise-element-selected') {
console.log('Selected element:', event.data);
// Use the data in your dashboard
const { selector, outerHTML, boundingBox } = event.data;
// Example: Create an experiment with this element
createExperiment({
targetSelector: selector,
originalHTML: outerHTML,
position: boundingBox
});
}
});{
"type": "optivise-element-selected",
"selector": "#hero h1",
"outerHTML": "<h1>Welcome to Our Site</h1>",
"boundingBox": {
"x": 100,
"y": 200,
"width": 500,
"height": 60
},
"timestamp": 1699564800000
}When running in visitor mode, the SDK expects a patch API endpoint:
GET https://api.optivise.dev/api/experiments/by-statsig-key/{statsigExperimentKey}/patch?variantKey={variant}&userId={userId}
{
"selector": "#hero h1",
"newHtml": "<h1 style='color: #10b981; font-size: 3rem;'>New Headline from Variant A!</h1>"
}- SDK initializes Statsig with
statsigClientKey - Retrieves variant from experiment using
experimentKey(must match thestatsigExperimentKeyfrom Optivise) - Calls patch API with
statsigExperimentKey,variantKey, anduserId - Applies
newHtmlto element matchingselector
Important: The experimentKey in your SDK config must match the statsigExperimentKey that was created when you created the experiment in the Optivise dashboard. This key is automatically generated and can be found in your experiment details.
In your Statsig experiment, add a parameter named variantKey:
- Control group:
variantKey = "control" - Variant A group:
variantKey = "variant_a" - Variant B group:
variantKey = "variant_b"
The SDK will skip patching for "control" variants.
<script
src="https://optivisesdk.pages.dev/optivise.js"
data-project="YOUR_PROJECT_ID">
</script><script>
window.OptiviseConfig = {
// Required for visitor mode
projectId: 'my-project',
statsigClientKey: 'client-YOUR_KEY',
// Optional
experimentKey: 'homepage_test', // Default: 'optv_default'
userID: 'user-123', // Default: anonymous
debug: true // Default: false
};
</script>
<script src="https://optivisesdk.pages.dev/optivise.js"></script>| Option | Required | Default | Description |
|---|---|---|---|
projectId |
No* | - | Your Optivise project ID (not used for patch fetching) |
statsigClientKey |
For visitor mode | - | Your Statsig client SDK key |
experimentKey |
For visitor mode | 'optv_default' |
Statsig experiment key (must match statsigExperimentKey from Optivise dashboard) |
userID |
No | anon_{timestamp} |
User identifier for Statsig |
debug |
No | false |
Enable detailed console logging |
* projectId is optional for visitor mode. The experimentKey is used to fetch patches from the API.
Method 1: URL Parameter (Recommended)
https://yoursite.com/?edit=true
Method 2: localStorage
localStorage.setItem('optivise_editor', 'on');
// Reload the pageWhen editor mode is active:
- A visual indicator appears in the top-right corner
- Hover over any element to see a highlight
- Click to select and emit data
- Press ESC to deselect (future enhancement)
- Node.js 16+
- npm 7+
# Install dependencies
npm install
# Build for production
npm run build
# Development mode (watch)
npm run dev- File:
dist/optivise.js - Format: IIFE (Immediately Invoked Function Expression)
- Size: ~23KB gzipped (includes Statsig SDK)
- Target: Modern browsers (ES6+)
# Start a local server
python3 -m http.server 8000
# Open test page
open http://localhost:8000/test.html?edit=true- Connect your GitHub repo
- Set build command:
npm run build - Set output directory:
dist - Deploy
Your SDK will be live at:
https://your-project.pages.dev/optivise.js
After deployment, add a custom domain in Cloudflare Pages:
cdn.optivise.dev → your-project.pages.dev
Then update your script tag:
<script src="https://cdn.optivise.dev/optivise.js"></script>Perfect for building experiment creation dashboards where users can:
- Navigate to their website with
?edit=true - Visually select elements they want to test
- Your dashboard captures the element data
- Create experiments based on selected elements
<!-- In your dashboard -->
<iframe src="https://clientsite.com/?edit=true"></iframe>
<script>
window.addEventListener('message', (event) => {
if (event.data.type === 'optivise-element-selected') {
// Show experiment modal with selected element
openExperimentModal(event.data);
}
});
</script>Use in a Chrome extension to capture elements across any site:
// content.js
chrome.runtime.onMessage.addListener((msg) => {
if (msg.type === 'enable-selector') {
// Inject Optivise SDK
const script = document.createElement('script');
script.src = 'https://cdn.optivise.dev/optivise.js';
document.body.appendChild(script);
// Activate editor mode
localStorage.setItem('optivise_editor', 'on');
location.reload();
}
});window.Optivise = {
version: '1.0.0', // SDK version
config: {}, // Current configuration
init: Function // Re-initialize SDK
}| Option | Type | Default | Description |
|---|---|---|---|
projectId |
string | null | Project identifier (optional) |
debug |
boolean | false | Enable debug logging |
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
Requires ES6+ support (modules, async/await, arrow functions).
- Size: ~23KB gzipped (includes Statsig SDK)
- Load Time: < 100ms
- Runtime Memory: < 500KB
- Editor mode: Zero impact when not activated
- Visitor mode: Minimal impact, async initialization
- ✅ Minimal dependencies (Statsig SDK only)
- ✅ Editor mode: No data sent to external servers
- ✅ Visitor mode: Patch data fetched from your API only
- ✅ Read-only DOM access in editor mode
- ✅ HTTPS only
- ✅ Content Security Policy compatible
If your site uses CSP, add:
Content-Security-Policy: script-src 'self' https://optivisesdk.pages.dev;
- Check URL has
?edit=true - Check browser console for errors
- Enable debug mode:
window.OptiviseConfig = { debug: true } - Verify script loaded: Check Network tab
- Check z-index conflicts with other elements
- Ensure no other scripts are interfering
- Try on a different page/site
- Check listener is set up before page loads
- Verify correct event type:
optivise-element-selected - Check iframe same-origin policies if using iframes
See test.html for a complete working example.
Q: Does this work with React/Vue/Angular?
A: Yes! Works with any framework. The SDK interacts with the final DOM.
Q: Can I use this in production?
A: Editor mode is for internal use only. Don't enable on production sites accessed by end users.
Q: Does it affect page performance?
A: Editor mode has zero impact when not activated. Visitor mode adds ~23KB (gzipped) and async initialization (~100ms). Minimal impact on page load.
Q: Can I customize the highlight color?
A: Currently no, but this can be added as a configuration option.
MIT
- 📧 Email: support@optivise.dev
- 🐛 Issues: GitHub Issues
- 📚 Docs: This README
Version: 1.0.0
Last Updated: November 2025