Web entitlements enable apps that sell subscriptions via web checkout (e.g., Stripe) to unlock premium features in the native app in real-time. After calling identify(), the SDK listens for entitlement changes automatically.
How It Works
- User purchases a subscription on your website.
- Your backend writes the entitlement to AppDNA.
- The SDK detects the change in real-time.
- Your app reacts via the callback and unlocks premium features.
Web entitlements are separate from in-app purchase entitlements. They are designed for apps that also sell subscriptions through a web checkout flow.
Check Current Entitlement
After identify(), the current web entitlement is available synchronously:
const entitlement = AppDNA.billing.webEntitlement;
if (entitlement && entitlement.is_active) {
unlockPremium();
console.log(`Plan: ${entitlement.plan_name}, Status: ${entitlement.status}`);
}
Listen for Changes
const unsubscribe = AppDNA.billing.onWebEntitlementChanged(
(entitlement: WebEntitlement | null) => {
if (entitlement?.is_active) {
unlockPremium();
} else {
lockPremium();
}
}
);
// Clean up
unsubscribe();
WebEntitlement
| Property | Type | Description |
|---|
is_active | boolean | Whether the subscription is currently active |
plan_name | string | Name of the subscription plan |
product_id | string | Product identifier |
status | string | Current status |
expires_at | string | null | Expiration date (ISO 8601) |
Entitlement Statuses
| Status | Description |
|---|
active | Subscription is active and paid |
trialing | User is in a free trial period |
past_due | Payment failed, in grace period |
canceled | Subscription is canceled |
Auto-Tracked Events
| Event | Trigger |
|---|
web_entitlement_activated | Web subscription becomes active |
web_entitlement_expired | Web subscription expires or is canceled |
Full Example
import { AppDNA, WebEntitlement } from "@appdna/react-native-sdk";
import React, { useEffect, useState } from "react";
function usePremiumAccess() {
const [hasAccess, setHasAccess] = useState(false);
useEffect(() => {
// Check on mount
checkAccess();
// Listen for web entitlement changes
const unsubscribe = AppDNA.billing.onWebEntitlementChanged(
(entitlement) => {
if (entitlement?.is_active) {
setHasAccess(true);
} else {
checkAccess();
}
}
);
return () => unsubscribe();
}, []);
async function checkAccess() {
// Check in-app purchase entitlements
const hasIAP = await AppDNA.billing.hasActiveSubscription();
if (hasIAP) {
setHasAccess(true);
return;
}
// Check web entitlement
const web = AppDNA.billing.webEntitlement;
setHasAccess(web?.is_active ?? false);
}
return hasAccess;
}
// Usage
function PremiumContent() {
const hasAccess = usePremiumAccess();
if (!hasAccess) {
return <UpgradePrompt />;
}
return <>{/* Premium content */}</>;
}
Web entitlements require Stripe integration configured in the Console under Settings > Billing > Web Payments. The real-time listener activates after identify() is called.