usePlacement hook is the primary way to display paywalls in your app. It manages paywall state and provides callbacks for all paywall lifecycle events.
Basic Usage
The registerPlacement Function
TheregisterPlacement function accepts a configuration object:
Placement Parameter
Theplacement string corresponds to placement IDs configured in your Superwall dashboard:
Custom Parameters
Pass additional data to customize paywall behavior:- Audience targeting rules
- A/B testing variants
- Paywall content customization
- Analytics tracking
Feature Callback
Thefeature callback executes when the user is allowed access:
The feature callback runs when:
- User is already subscribed
- User successfully purchases through the paywall
- User is in a holdout group
- No audience rules match (paywall not shown)
Lifecycle Callbacks
TheusePlacement hook accepts callback functions for all paywall events:
Callback Types
onPresent
Called when a paywall is displayed to the user.paywallInfo object includes:
identifier- Unique paywall IDname- Paywall name from dashboardproducts- Available productsexperiment- A/B test informationpresentedByEventWithName- The placement that triggered it- And more (see
/home/daytona/workspace/source/src/SuperwallExpoModule.types.ts:392)
onDismiss
Called when the paywall is closed.result object can be:
onSkip
Called when a paywall is not shown.onError
Called when an error occurs during paywall presentation.Paywall State
The hook returns astate object tracking the current paywall status:
State Types
Using State in UI
Complete Example
Here’s a full implementation with all features:Multiple Placements
You can use multipleusePlacement hooks for different features:
Best Practices
Use descriptive placement names
Use descriptive placement names
Name placements based on features or user actions:
- ✅
premium_export,remove_ads,onboarding - ❌
paywall1,test,screen2
Track analytics in callbacks
Track analytics in callbacks
Use callbacks to track important metrics:
Handle all result types
Handle all result types
Check all possible result types in
onDismiss:Pass meaningful parameters
Pass meaningful parameters
Include context in placement params:
Next Steps
Managing Users
Learn about user identification and attributes
Preloading Paywalls
Improve performance by preloading paywalls