How It Works
Script Injection
On mount (client-side only via useEffect):
- Checks for existing script with
id="mvt-engine-script" - If missing, creates
<script>with:src="https://staging-svc.mvtlab.io/scripts/engine.js"data-project-key={orchestratorKey}data-mvt="engine"async={true}
- Appends to
<head>
This ensures one script per page, even on re-renders.
Anti-Flicker
When antiFlickerEnabled={true}:
- Injects
<style id="abhide">body{opacity:0}</style>into<head> - Defines
window.rmfk()to remove the style element - Engine calls
window.rmfk()when ready - Safety timeout (default 3000ms) calls
window.rmfk()as fallback
The id="abhide" matches the original HTML snippet's style identifier. The function name rmfk stands for "remove flicker"—a callback the engine uses to signal readiness.
Project Key Validation
- Stores
orchestratorKeyinwindow.__mvtOrchestratorKeyon mount - If a different key is detected, logs error and skips script injection
- Enforces one key per website (wrap once at root)
Technical Details
This package wraps the standard MVTLab.io HTML integration snippet into a React component. The original snippet uses an IIFE pattern with document, window, and a timeout—this SDK translates that into React hooks and TypeScript types.