1. Pick a loading strategy
| Strategy | When to use | Requirements |
|---|---|---|
| Synchronous (blocking) | You want the simplest setup and can tolerate the script being parsed during the initial render. | Only the SDK tag inside <head>. |
| Asynchronous (non-blocking) | You need the main thread free during the first paint (e.g. performance-critical landing pages). | A short anti-flicker snippet plus the SDK tag with async. |
data-client-key attribute that you will find in your pagent workspace.
2. Synchronous loading
Add the tag as early as possible inside the<head> tag:
Because the tag must execute before the page is painted, we do not recommend inserting it via Google Tag Manager or any tool that injects scripts late.
3. Asynchronous loading with anti-flicker
- Paste the anti-flicker snippet right after the opening
<head>tag:
MAX_WAIT if you can accept the risk that variations might not be applied in time.
If you prefer a minified version:
- Load the SDK asynchronously:
4. Skip page hide (no flicker)
If you want to disable the page-hiding mechanism entirely, you can add thedata-skip-page-hide="true" attribute to the SDK script tag. This prevents the SDK from hiding the page during initialization.
async attribute for asynchronous loading:
- ✅ No page hiding – The page remains visible throughout initialization
- ✅ No flicker – Users won’t see the page fade in/out
- ⚠️ Content overwrite – Variations are applied directly to the visible page
- ⚠️ Brief flash possible – Users may see the original content briefly before it’s replaced with variations
- When you prefer no visual hiding/flicker over perfect content replacement
- When your variations are subtle and a brief flash is acceptable
- When you want to avoid any opacity changes to the page body
- When using with asynchronous loading and you don’t want the anti-flicker snippet
data-skip-page-hide="true" with asynchronous loading, you do not need to include the anti-flicker snippet from section 3.
5. Analytics only mode
For scenarios where you only need to track analytics data without running tests, you can use the SDK in “analytics only mode” by adding thedata-analytics-only="true" attribute:
- ✅ Tracks analytics and user behavior data
- ✅ Makes the
_pgntproperty available for custom tracking - ❌ Never loads or runs A/B tests
- ❌ Never overwrites variations or content
- ❌ Never loads anti-flicker mechanisms
- Analytics tracking without experimentation
- Gradual migration from other analytics tools
- Testing pagent’s data collection before enabling experiments
- Compliance scenarios where you need data but not content changes
6. Best practices & troubleshooting
- Keep it fast – The SDK is delivered from our global CDN and is heavily cached. Still, monitor Web Vitals to ensure no regressions.
- Avoid flicker – In both modes the SDK temporarily sets
body{opacity:0}. This usually lasts less than 50 ms, but audit on slow connections. - Test first – Roll out the integration to a staging environment before production.
- Need help? – Reach out at support@pagent.ai.