Encore requires user identification to track entitlements and prevent abuse across devices. You can also set user attributes to enable targeted offers and personalization.
Encore automatically generates a random user ID that persists in localStorage until the user clears their browser data or you call reset().This anonymous ID allows entitlement tracking to work immediately without requiring explicit user identification. The auto-generated ID is a standard UUID (e.g., 550e8400-e29b-41d4-a716-446655440000).
Copy
import Encore from '@encore/web-sdk';// Configure SDKEncore.configure({ apiKey: 'pk_your_api_key_here' });// Get auto-generated user IDconst userId = Encore.getCurrentUserId();console.log('User ID:', userId); // UUID format
The anonymous ID is stored in localStorage with a fallback to sessionStorage if localStorage is unavailable.
After login - When a user successfully authenticates
After signup - When a new user creates an account
On page load - If you already have the user’s ID from session/cookies
After authentication check - When restoring a user session
React
Vue
Angular
Svelte
Vanilla JS
Copy
import { useEffect } from 'react';import Encore from '@encorekit/web-sdk';function App() { useEffect(() => { // Check if user is logged in const user = getCurrentUser(); // Your auth function if (user) { Encore.identify(user.id, { email: user.email, subscriptionTier: user.tier }); } }, []); return <YourApp />;}
Copy
import { onMounted } from 'vue';import Encore from '@encorekit/web-sdk';export default { setup() { onMounted(() => { // Check if user is logged in const user = getCurrentUser(); // Your auth function if (user) { Encore.identify(user.id, { email: user.email, subscriptionTier: user.tier }); } }); }};
Copy
import { Component, OnInit } from '@angular/core';import { EncoreService } from './encore.service';import { AuthService } from './auth.service';@Component({ selector: 'app-root', template: '<router-outlet></router-outlet>'})export class AppComponent implements OnInit { constructor( private encoreService: EncoreService, private authService: AuthService ) {} ngOnInit() { // Check if user is logged in this.authService.currentUser$.subscribe(user => { if (user) { this.encoreService.identify(user.id, { email: user.email, subscriptionTier: user.tier }); } }); }}
Copy
<script lang="ts"> import { onMount } from 'svelte'; import Encore from '@encorekit/web-sdk'; import { user } from './stores/auth'; onMount(() => { // Subscribe to user store const unsubscribe = user.subscribe($user => { if ($user) { Encore.identify($user.id, { email: $user.email, subscriptionTier: $user.tier }); } }); return unsubscribe; });</script><YourApp />
Copy
// On page loaddocument.addEventListener('DOMContentLoaded', () => { var EncoreSDK = Encore.default || Encore; var user = getCurrentUser(); // Your auth function if (user) { EncoreSDK.identify(user.id, { email: user.email, subscriptionTier: user.tier }); }});
Attributes are merged, so you can update them incrementally:
Copy
// Set initial attributesEncore.setUserAttributes({ subscriptionTier: 'free', monthsSubscribed: '0'});// Later, update specific attributesEncore.setUserAttributes({ monthsSubscribed: '6', custom: { featureUsage: 'high' }});// Previous subscriptionTier is still set