Skip to main content
Configures the Encore SDK for use throughout your application. This must be called once, typically before your app renders, before using any other SDK methods.
Call configure() before using any other SDK methods. Only the first call is honored - subsequent calls will be ignored with a warning.

Signature

function configure(config: EncoreConfig): void

Parameters

config
EncoreConfig
required
Configuration object for the SDK
interface EncoreConfig {
  apiKey: string
  userId: string 
  environment?: 'production' | 'development'
  logLevel?: 'none' | 'debug'
  uiConfiguration?: UIConfiguration
}
config.apiKey
string
required
Your public API key from the Encore Dashboard. This key identifies your app and is safe to use in client-side code.
apiKey: 'pk_live_1234567890abcdef'
Get your API key from the Encore Dashboard
config.userId
string
required
Unique identifier for the user. This should persist across sessions and be set before user authentication.
userId: 'user-123'
Best Practices:
  • Generate an anonymous ID on first visit and store in localStorage
  • Use opaque identifiers (not email or sensitive data)
  • Keep consistent across sessions for accurate tracking
  • Can be different from the ID used in identify()
Example ID Generation:
const storageKey = 'encore_user_id';
let userId = localStorage.getItem(storageKey);

if (!userId) {
  userId = 'user_' + Math.random().toString(36).substring(2, 15);
  localStorage.setItem(storageKey, userId);
}
Never use personally identifiable information (email, SSN, etc.) as the userId. Use opaque identifiers only.
config.environment
string
default:"production"
API environment to use. Options: 'production' or 'development'.
  • production: https://svc.joinyaw.com/product/encore/v1 (default)
  • development: http://localhost:8080/encore/v1 (for local testing)
environment: 'production'
config.logLevel
string
default:"none"
Debug logging level. Options: 'none' or 'debug'.
  • none: No debug logs (recommended for production)
  • debug: Verbose logging for development
logLevel: 'debug'
config.uiConfiguration
UIConfiguration
Customize the text displayed in the offer modal. All fields are optional.
interface UIConfiguration {
  titleText?: string
  subtitleText?: string
  offerDescriptionText?: string
  instructionsTitleText?: string
  lastStepHeaderText?: string
  lastStepDescriptionText?: string
  creditClaimedTitleText?: string
  creditClaimedSubtitleText?: string
  applyCreditsButtonText?: string
}
uiConfiguration: {
  titleText: 'Get Premium Access',
  subtitleText: 'Complete a quick offer to unlock features'
}

Return Value

Type: void The method doesn’t return a value. It configures the SDK for subsequent use.

Examples

Basic Configuration

import Encore from '@encorekit/web-sdk';

// Generate or retrieve userId
const storageKey = 'encore_user_id';
let userId = localStorage.getItem(storageKey);

if (!userId) {
  userId = 'user_' + Math.random().toString(36).substring(2, 15);
  localStorage.setItem(storageKey, userId);
}

Encore.configure({
  apiKey: 'pk_your_api_key_here',
  userId: userId 
});

Full Configuration

import Encore from '@encorekit/web-sdk';

Encore.configure({
  apiKey: 'pk_your_api_key_here',
  userId: 'user-abc123',
  environment: 'production',
  logLevel: 'debug',
  uiConfiguration: {
    titleText: 'Unlock Premium Features',
    subtitleText: 'Complete an offer to get instant access',
    creditClaimedTitleText: 'Success! 🎉',
    creditClaimedSubtitleText: 'Your premium access is now active'
  }
});

With Environment Variables

  • Vite (Vue/Svelte)
  • React (CRA)
  • Angular
const storageKey = 'encore_user_id';
let userId = localStorage.getItem(storageKey);
if (!userId) {
  userId = 'user_' + Math.random().toString(36).substring(2, 15);
  localStorage.setItem(storageKey, userId);
}

Encore.configure({
  apiKey: import.meta.env.VITE_ENCORE_API_KEY,
  userId: userId,
  logLevel: import.meta.env.MODE === 'development' ? 'debug' : 'none'
});

Framework Integration

  • React
  • Vue
  • Angular
  • Next.js
  • Svelte
  • Vanilla JS
App.tsx
import { useEffect } from 'react';
import Encore from '@encorekit/web-sdk';

function App() {
  useEffect(() => {
    // Generate or retrieve userId
    const storageKey = 'encore_user_id';
    let userId = localStorage.getItem(storageKey);
    
    if (!userId) {
      userId = 'user_' + Math.random().toString(36).substring(2, 15);
      localStorage.setItem(storageKey, userId);
    }
    
    Encore.configure({
      apiKey: process.env.REACT_APP_ENCORE_API_KEY,
      userId: userId,
      environment: 'production'
    });
  }, []);

  return <div>Your App</div>;
}

UI Customization

Customize all text in the offer modal:
Encore.configure({
  apiKey: 'pk_your_api_key_here',
  userId: 'user-123',
  uiConfiguration: {
    // Header
    titleText: 'Special Offer',
    subtitleText: 'Complete a task to get rewards',
    
    // Offer section
    offerDescriptionText: 'Choose an offer below to get started',
    
    // Instructions
    instructionsTitleText: 'How It Works',
    
    // Last step
    lastStepHeaderText: 'Almost Done',
    lastStepDescriptionText: 'Complete the advertiser\'s requirements',
    
    // Success screen
    creditClaimedTitleText: 'Congratulations!',
    creditClaimedSubtitleText: 'You\'ve unlocked premium access',
    applyCreditsButtonText: 'Get Started'
  }
});

Best Practices

1. Generate Persistent User IDs

Always generate and persist user IDs in localStorage:
function getOrCreateUserId() {
  const storageKey = 'encore_user_id';
  let userId = localStorage.getItem(storageKey);
  
  if (!userId) {
    userId = 'user_' + Math.random().toString(36).substring(2, 15);
    localStorage.setItem(storageKey, userId);
  }
  
  return userId;
}

const userId = getOrCreateUserId();
Encore.configure({ apiKey: 'your-key', userId });

2. Configure Early

Call configure() as early as possible in your app lifecycle:
// Good: Configure before app initialization
const userId = getOrCreateUserId();
Encore.configure({ apiKey: 'your-key', userId });
initApp();

// Avoid: Configuring inside components
function MyComponent() {
  Encore.configure({ apiKey: 'your-key', userId: 'user-123' }); // ❌ Too late
}

3. Use Environment Variables

Never hardcode API keys:
// Good
Encore.configure({
  apiKey: process.env.ENCORE_API_KEY,
  userId: getOrCreateUserId()
});

// Avoid
Encore.configure({
  apiKey: 'pk_live_abc123', // ❌ Hardcoded
  userId: 'user-123'
});

4. Enable Debug Logging in Development

Encore.configure({
  apiKey: 'your-key',
  userId: getOrCreateUserId(),
  logLevel: process.env.NODE_ENV === 'development' ? 'debug' : 'none'
});

5. Configure Once

Don’t call configure() multiple times:
// Good: Single configuration
Encore.configure({ apiKey: 'your-key', userId: 'user-123' });

// Avoid: Multiple calls
Encore.configure({ apiKey: 'your-key', userId: 'user-123' });
Encore.configure({ logLevel: 'debug' }); // ⚠️ Ignored

6. User ID vs Identity

The userId in configure is for tracking. Use identify() for personalization:
// Step 1: Configure with tracking ID
Encore.configure({
  apiKey: 'your-key',
  userId: 'anonymous-user-123'
});

// Step 2: After login, identify with real user data
Encore.identify('authenticated-user-456', {
  email: 'user@example.com',
  subscriptionTier: 'premium'
});

Utility Methods

getCurrentUserId()

Get the user ID that was provided during configuration:
const userId = Encore.getCurrentUserId();
console.log('Current user ID:', userId); // "user-abc123"

getVersion()

Get the current SDK version:
const version = Encore.getVersion();
console.log('SDK version:', version); // "0.1.1"

setLogLevel()

Change the log level after initialization:
// Enable debug logging
Encore.setLogLevel('debug');

// Disable debug logging
Encore.setLogLevel('none');

Troubleshooting

Symptom: SDK throws error about missing userId parameterSolution: Add the userId parameter to your configuration:
const userId = getOrCreateUserId(); // Implement this function
Encore.configure({
  apiKey: 'your-key',
  userId: userId 
});
See Migration from v0.1.0 for details.
Symptom: Warning about duplicate configuration callsSolution:
  • configure() should only be called once
  • Subsequent calls are ignored
  • First configuration is used
  • If you need to reconfigure, reload the page
Symptom: Unauthorized or API errorsSolutions:
  1. Verify your API key is correct in the Dashboard
  2. Ensure you’re using the public API key (starts with pk_)
  3. Check that your API key hasn’t been revoked
  4. Verify the package name is @encorekit/web-sdk
  5. Contact admin@encorekit.com if issues persist
Symptom: Type errors in configurationSolution:
  • Ensure @encorekit/web-sdk is installed
  • TypeScript types are included automatically
  • Use proper type imports if needed:
import type { EncoreConfig } from '@encorekit/web-sdk';

const config: EncoreConfig = {
  apiKey: 'pk_your_key',
  userId: 'user-123'
};
Symptom: In vanilla JS, getting “Encore.configure is not a function”Solution: Use the UMD export pattern:
const EncoreSDK = Encore.default || Encore;
EncoreSDK.configure({
  apiKey: 'your-key',
  userId: 'user-123'
});

Next Steps

After configuration, continue with: For complete working examples, visit our Examples repository.