Monetize with subscriptions
Last updated
Was this helpful?
Was this helpful?
const TIUN_PRODUCTS = {
light: 'p-live-light',
pro: 'p-live-pro',
};function onClickLight() {
tiun.checkout({ productId: TIUN_PRODUCTS.light });
}
function onClickPro() {
tiun.checkout({ productId: TIUN_PRODUCTS.pro });
}tiun.on('userChange', (data) => {
if (data.event === 'checkout' && data.user) {
console.log('Subscribed to:', data.user.productAccess);
}
});tiun.on('userChange', (data) => {
if (!data.isAuthenticated) {
showPricingPage();
return;
}
const hasProAccess = data.user.productAccess.includes(TIUN_PRODUCTS.pro);
const hasLightAccess = data.user.productAccess.includes(TIUN_PRODUCTS.light);
if (hasProAccess) {
showProContent();
} else if (hasLightAccess) {
showLightContent();
} else {
showUpgradePrompt();
}
});import { tiun } from '@tiun/sdk';
const TIUN_PRODUCTS = {
light: 'p-live-light',
pro: 'p-live-pro',
};
tiun.on('userChange', (data) => {
if (!data.isAuthenticated) {
showPricingPage();
return;
}
const hasProAccess = data.user.productAccess.includes(TIUN_PRODUCTS.pro);
const hasLightAccess = data.user.productAccess.includes(TIUN_PRODUCTS.light);
if (hasProAccess) {
showProContent();
} else if (hasLightAccess) {
showLightContent();
} else {
showUpgradePrompt();
}
});
tiun.init({
snippetId: 'YOUR_SNIPPET_ID',
language: 'en',
});
function checkoutLight() {
tiun.checkout({ productId: TIUN_PRODUCTS.light });
}
function checkoutPro() {
tiun.checkout({ productId: TIUN_PRODUCTS.pro });
}