import Encore from '@encorekit/web-sdk';
Encore.configure({ apiKey: 'pk_live_yourpublishablekey' }); // deferred is the default mode
Encore.identify(userId); // bind the claim to an id that survives reloads
// 1. The user dismisses your paywall without subscribing
async function onPaywallAbandoned() {
const result = await Encore.placement('paywall_abandon', {
appearance: { accentColor: '#2E6BFF' },
// display: { appDisplayName: 'FitTracker', trialPeriod: '1 month' },
// ^ only if you don't manage the app name / entitlement / icon in the portal
}).show();
if (result.status !== 'claimed') {
return; // 'dismissed' | 'unavailable': continue your normal exit path
}
// 2. Claim recorded, no redirect. The SDK's primer screen has handed the
// user off. Now sell YOUR OWN exclusive offer: the extended free trial.
openTrialCheckout(); // your checkout: "1 month free (usually 7 days), then $9.99/mo"
}
// 3. After the user purchases your exclusive offer, from a click/flow handler:
async function onTrialCheckoutComplete() {
const outcome = await Encore.placement('paywall_abandon').redeem();
// outcome.status === 'redeemed': the redemption screen showed the user's
// new plan and sent them to the partner on the CTA tap.
}