Blox
Pelcro Integration Guide for Blox
A quick-start guide for Blox users to integrate Pelcro's subscription management, paywalls, and user authentication.
Table of Contents
- Adding the Pelcro Script
- Adding Login & Subscribe Buttons
- Implementing the Paywall
- Using URL Triggers
- Implementing the User Dashboard
- E-Reader Integration
1. Adding the Pelcro Script
Add this code to your site's <head> section:
<script>
window.Pelcro = {};
window.Pelcro.siteid = 1232; // replace with your PRODUCTION Site ID
window.Pelcro.environment = {
domain: "https://www.pelcro.com",
ui: "https://ui.pelcro.com/bundle.js",
stripe: "pk_live_Wdef2LjEQXsgFWult6IVFobB"
};
</script>
<script defer src="https://js.pelcro.com/sdk/main.min.js" type="text/javascript"></script>Do not self-host the script — always load from Pelcro's CDN to receive automatic updates.
2. Adding Login & Subscribe Buttons
Login Button
<button class="pelcro-login-button">Sign In</button>Subscribe Button
<!-- Basic -->
<button class="pelcro-subscribe-button">Subscribe</button>
<!-- Pre-select a plan -->
<button class="pelcro-subscribe-button"
data-product-id="123"
data-plan-id="456">
Subscribe to Premium
</button>All Button Classes
| Class | Function | Attributes |
|---|---|---|
pelcro-login-button | Login / Dashboard | data-login-text, data-dashboard-text |
pelcro-register-button | Registration | — |
pelcro-subscribe-button | Subscription flow | data-product-id, data-plan-id |
pelcro-dashboard-button | User dashboard | — |
pelcro-gift-button | Gift purchase | data-product-id, data-plan-id |
pelcro-cart-button | Shopping cart | — |
pelcro-add-to-cart-button | Add to cart | data-sku-id (required) |
pelcro-purchase-button | Direct purchase | data-sku-id (required) |
pelcro-update-newsletters-button | Newsletter prefs | — |
pelcro-offline-subscribe-button | Offline plans | data-product-id, data-plan-id |
pelcro-manage-members-button | Manage members | data-subscription-id |
3. Implementing the Paywall
Paywalls are configured in your Pelcro Dashboard — no code required.
- Go to Products → click ... → Configure
- Set as Paywall Product
- Choose targeting: metered (X free articles) or premium (full restriction)
Client-Side Content Protection (Optional)
Blur content for non-subscribers:
<div data-pelcro-entitlements="premium">
This content is blurred until user subscribes
</div>
<!-- With pre-selected plan -->
<div data-pelcro-entitlements="premium"
data-product-id="123"
data-plan-id="456">
Protected content
</div>4. Using URL Triggers
Open Pelcro modals via URL parameters.
Basic Triggers
| Action | URL |
|---|---|
| Login | ?view=login |
| Register | ?view=register |
| Plan Selection | ?view=plan-select |
| Gift Redemption | ?view=gift-redeem |
| Password Reset | ?view=password-forgot |
| Edit Profile | ?view=user-edit |
| Newsletter | ?view=newsletter |
With Parameters
| Action | URL |
|---|---|
| Specific Plan | ?view=plan-select&product_id=123&plan_id=456 |
| Apply Coupon | ?view=plan-select&coupon_code=SAVE20 |
| Gift Purchase | ?view=plan-select&is_gift=true |
| Redeem Gift Code | ?view=gift-redeem&gift_code=ABC123 |
| Update Payment | ?view=payment-method-update&source_id=XXX |
| Newsletter Update | ?view=newsletter-update&[email protected] |
| Cart with Items | ?view=cart&sku_id=32,33,34 |
5. Implementing the User Dashboard
Option A: Login Button (Recommended)
Shows login for guests, dashboard for authenticated users:
<button class="pelcro-login-button"
data-login-text="Sign In"
data-dashboard-text="My Account">
Sign In
</button>Option B: Dashboard Only
<button class="pelcro-dashboard-button">My Account</button>Customization
<script>
window.Pelcro = {};
window.Pelcro.siteid = YOUR_SITE_ID;
window.Pelcro.uiSettings = {
enableLoginWithUsername: true,
enableNameFieldsInRegister: true,
membershipSubscriptionStatusAccess: ["active", "trialing", "past_due"],
newsletters: [
{ "id": "daily", "label": "Daily Digest" }
]
};
</script>
<script defer src="https://js.pelcro.com/sdk/main.min.js"></script>6. E-Reader Integration
Check Subscription Status
document.addEventListener('PelcroUserLoggedIn', function() {
const subscriptions = window.Pelcro.subscription.list() || [];
const hasAccess = subscriptions.some(sub =>
['active', 'trialing', 'extended'].includes(sub.status)
);
if (hasAccess) {
// Grant e-Reader access
}
});Check Entitlement-Based Access
// If you've configured entitlements in Pelcro Dashboard
if (window.Pelcro.user.isEntitledTo('ereader-access')) {
// Grant e-Reader access
}Require Login for E-Reader
if (!window.Pelcro.user.isAuthenticated()) {
window.location.href = '?view=login';
}Subscription Status Reference
| Status | Description |
|---|---|
active | Active subscription |
trialing | In trial period |
extended | Grace period access |
past_due | Payment overdue (optional) |
canceled | Canceled |
expired | Expired |
document.addEventListener('PelcroUserLoggedIn', function() {
const { subscriptions } = window.Pelcro.user.read();
const hasAccess = subscriptions?.some(sub =>
['active', 'trialing'].includes(sub.status)
);
if (hasAccess) {
// Grant e-Reader access
}
});Require Login for E-Reader
if (!window.Pelcro.user.isAuthenticated()) {
window.location.href = '?view=login';
}JavaScript Events
Listen for Pelcro events:
// User logged in
document.addEventListener('PelcroUserLoggedIn', callback);
// User logged out
document.addEventListener('PelcroUserLogout', callback);
// Subscription created
document.addEventListener('PelcroSubscriptionCreate', callback);
// Paywall displayed
document.addEventListener('PelcroPaywallDisplayed', callback);
// Paywall triggered (with article counts)
document.addEventListener('PelcroPaywallMatch', function(e) {
console.log(e.detail.count_of_articles_read);
console.log(e.detail.count_of_articles_left);
});
// Modal opened
document.addEventListener('PelcroModalDisplay', function(e) {
console.log('Modal:', e.detail.modalName);
});Support
- React Elements: https://docs-react-elements.pelcro.com
Updated 2 days ago
