Prerequisites
- A React or Next.js frontend
- AdMesh API key
Step 1: Install the SDK
Step 2: Generate Session ID and Wrap Your Page
For publisher integrations, use the SDK’s utility function to generate session IDs from URL structure.How Session Generation Works
TheAdMeshSDK.generateSessionIdFromUrl() utility function:
- Extracts article slug from the current page URL path
- Generates format:
session_{timestamp}_{article-slug} - Handles errors gracefully with fallback to random session ID
https://techcrunch.com/2025/12/30/the-best-ai-powered-dictation-apps-of-2025/→session_1739534760000_the-best-ai-powered-dictation-apps-of-2025https://example.com/blog/how-to-build-react-apps→session_1739534760000_how-to-build-react-apps
For Non-Publisher API Keys
If you’re using a non-publisher API key (e.g.,sk_ keys), generate session IDs manually:
Session Management Best Practices
For Publishers:- Use
AdMeshSDK.generateSessionIdFromUrl()for URL-based sessions - Call this function on every page load
- The utility handles edge cases and errors automatically
- Use
AdMeshSDK.createSession()for random session IDs - Implement your own persistence strategy if needed
- Store session IDs in localStorage, cookies, or server-side
Optional: Custom Session ID
You can always override with a custom session ID:Step 3: Configure Environment Variables
Use a valid
pub_ key for publisher integrations. The pub_ prefix enables automatic session ID detection. Inject it from your app config or backend, and avoid hardcoding keys in production.Step 4: Verify Integration
- Open a content page where the assistant is rendered
- Confirm the floating assistant appears in the selected corner
- Click a suggestion and verify recommendation UI appears
- Check browser console for SDK initialization logs
Next Step
UI SDK Integration
Explore advanced configuration options for AdMeshIntentAssistant.