Initialize Encore in Your App
The SDK must be configured before calling any other methods. Callconfigure() as early as possible in your application lifecycle with both your API key and a user ID.
User ID Requirement
You must provide auserId when configuring the SDK. This ID should:
- Be unique per user
- Persist across sessions (use localStorage or your auth system)
- Be set before the user authenticates (use anonymous ID if needed)
Framework-Specific Examples
Choose your framework below to see the complete setup:- React
- Vue
- Angular
- Next.js
- Svelte
- Vanilla JS
App.tsx
.env file:Configuration Options
Your public API key from the Encore Dashboard. Get yours at dashboard.encorekit.com.
Unique identifier for the user. Should persist across sessions. Use an anonymous ID before authentication, then associate with real user via
identify().Runtime environment. Use
'development' for local testing with additional logging.Controls SDK logging verbosity. Use
'debug' during development to see detailed logs.User ID Best Practices
Generate Anonymous IDs
Generate a persistent anonymous ID for users before they log in:Link to Authenticated Users
After user login, associate the anonymous ID with their real account:Security Considerations
Verify Configuration
After configuring, verify the SDK is initialized:Next Steps
Now that the SDK is configured, continue with:- Identify Users - Associate users with offers after login
- Present Offers - Display targeted offers to users
- Track Entitlements - Validate user entitlements server-side
Troubleshooting
Error: userId is required
Error: userId is required
Problem: SDK throws error about missing userId parameter.Solution: Add the
userId parameter to your configuration:Vanilla JS: Encore.configure is not a function
Vanilla JS: Encore.configure is not a function
Problem: In vanilla JS, getting “Encore.configure is not a function”.Solution: Use the UMD export pattern:
User ID changes on every page load
User ID changes on every page load
Problem: Users are getting a new ID on each visit.Solution: Ensure you’re persisting the userId in localStorage:
Environment variables not working
Environment variables not working
Problem: API key is undefined at runtime.Solution: Make sure your environment variable has the correct prefix:
- React:
REACT_APP_prefix - Vite (Vue/Svelte):
VITE_prefix - Next.js:
NEXT_PUBLIC_prefix - Angular: Configure in
environment.ts