# useSuperwallEvents

Purpose [#purpose]

The `useSuperwallEvents` hook provides a low-level way to subscribe to *any* native Superwall event. This is useful for advanced use cases or for events not covered by the more specific hooks. Listeners are automatically cleaned up when the component using this hook unmounts.

Parameters [#parameters]

<TypeTable
  type="{
  callbacks: {
    type: &#x22;SuperwallEventCallbacks?&#x22;,
    description: &#x22;Object of event callbacks to subscribe to. Omit any you do not need.&#x22;,
  },
}"
/>

SuperwallEventCallbacks [#superwalleventcallbacks]

<TypeTable
  type="{
  onPaywallPresent: {
    type: &#x22;(paywallInfo: PaywallInfo) => void&#x22;,
    description: &#x22;Called when a paywall is presented.&#x22;,
  },
  onPaywallDismiss: {
    type: &#x22;(paywallInfo: PaywallInfo, result: PaywallResult) => void&#x22;,
    description: &#x22;Called when a paywall is dismissed.&#x22;,
  },
  onPaywallSkip: {
    type: &#x22;(reason: PaywallSkippedReason) => void&#x22;,
    description: &#x22;Called when a paywall is skipped.&#x22;,
  },
  onPaywallError: {
    type: &#x22;(error: string) => void&#x22;,
    description: &#x22;Called when paywall presentation fails or another SDK error occurs.&#x22;,
  },
  onSubscriptionStatusChange: {
    type: &#x22;(status: SubscriptionStatus) => void&#x22;,
    description: &#x22;Called when the user's subscription status changes.&#x22;,
  },
  onUserAttributesChange: {
    type: &#x22;(newAttributes: Record<string, any | null>) => void&#x22;,
    description:
      &#x22;Called when user attributes change outside your app (for example via the `Set Attribute` paywall action).&#x22;,
  },
  onSuperwallEvent: {
    type: &#x22;(eventInfo: SuperwallEventInfo) => void&#x22;,
    description: &#x22;Called for generic Superwall events with payload metadata.&#x22;,
  },
  onCustomPaywallAction: {
    type: &#x22;(name: string) => void&#x22;,
    description: &#x22;Called when a custom action is triggered from a paywall.&#x22;,
  },
  willDismissPaywall: {
    type: &#x22;(paywallInfo: PaywallInfo) => void&#x22;,
    description: &#x22;Called just before a paywall is dismissed.&#x22;,
  },
  willPresentPaywall: {
    type: &#x22;(paywallInfo: PaywallInfo) => void&#x22;,
    description: &#x22;Called just before a paywall is presented.&#x22;,
  },
  didDismissPaywall: {
    type: &#x22;(paywallInfo: PaywallInfo) => void&#x22;,
    description: &#x22;Called after a paywall has been dismissed.&#x22;,
  },
  didPresentPaywall: {
    type: &#x22;(paywallInfo: PaywallInfo) => void&#x22;,
    description: &#x22;Called after a paywall has been presented.&#x22;,
  },
  onPaywallWillOpenURL: {
    type: &#x22;(url: string) => void&#x22;,
    description: &#x22;Called when the paywall attempts to open a URL.&#x22;,
  },
  onPaywallWillOpenDeepLink: {
    type: &#x22;(url: string) => void&#x22;,
    description: &#x22;Called when the paywall attempts to open a deep link.&#x22;,
  },
  onLog: {
    type: &#x22;(params: { level: LogLevel; scope: LogScope; message: string | null; info: Record<string, any> | null; error: string | null }) => void&#x22;,
    description: &#x22;Called for log messages emitted by the SDK.&#x22;,
  },
  willRedeemLink: {
    type: &#x22;() => void&#x22;,
    description: &#x22;Called before the SDK attempts to redeem a promotional link.&#x22;,
  },
  didRedeemLink: {
    type: &#x22;(result: RedemptionResult) => void&#x22;,
    description: &#x22;Called after the SDK attempts to redeem a promotional link.&#x22;,
  },
  onPurchase: {
    type: &#x22;(params: OnPurchaseParams) => void&#x22;,
    description: &#x22;Called when a purchase is initiated. Params differ by platform.&#x22;,
  },
  onPurchaseRestore: {
    type: &#x22;() => void&#x22;,
    description: &#x22;Called when a purchase restore is initiated.&#x22;,
  },
  onBackPressed: {
    type: &#x22;(paywallInfo: PaywallInfo) => boolean&#x22;,
    description:
      &#x22;Android only. Triggered when a rerouted paywall back button is pressed. Return true to consume the event.&#x22;,
  },
  onCustomCallback: {
    type: &#x22;(callback: CustomCallback) => Promise<CustomCallbackResult> | CustomCallbackResult&#x22;,
    description:
      &#x22;Called when a custom callback is invoked from a paywall. Custom callbacks allow paywalls to communicate with the app to perform operations like validation or data fetching. Return a result to send back to the paywall.&#x22;,
  },
  handlerId: {
    type: &#x22;string?&#x22;,
    description: &#x22;Optional scope for paywall events from a specific registerPlacement handler.&#x22;,
  },
}"
/>

SuperwallEventInfo [#superwalleventinfo]

<TypeTable
  type="{
  event: {
    type: &#x22;SuperwallEvent&#x22;,
    description: &#x22;The native Superwall event payload. For multi-page paywalls, this can be a PaywallPageViewEvent.&#x22;,
    required: true,
  },
  params: {
    type: &#x22;Record<string, any>&#x22;,
    description: &#x22;Additional payload metadata for the event.&#x22;,
    required: true,
  },
}"
/>

PageViewData [#pageviewdata]

<TypeTable
  type="{
  pageNodeId: {
    type: &#x22;string&#x22;,
    description: &#x22;Unique identifier for the page node.&#x22;,
    required: true,
  },
  flowPosition: {
    type: &#x22;number&#x22;,
    description: &#x22;Zero-based page position in the paywall flow.&#x22;,
    required: true,
  },
  pageName: {
    type: &#x22;string&#x22;,
    description: &#x22;Display name for the page.&#x22;,
    required: true,
  },
  navigationNodeId: {
    type: &#x22;string&#x22;,
    description: &#x22;Unique identifier for the navigation node.&#x22;,
    required: true,
  },
  previousPageNodeId: {
    type: &#x22;string?&#x22;,
    description: &#x22;Previous page node identifier, when available.&#x22;,
  },
  previousFlowPosition: {
    type: &#x22;number?&#x22;,
    description: &#x22;Previous page position in the paywall flow, when available.&#x22;,
  },
  navigationType: {
    type: &#x22;\&#x22;entry\&#x22; | \&#x22;forward\&#x22; | \&#x22;back\&#x22; | \&#x22;auto_transition\&#x22; | string&#x22;,
    description: &#x22;How the user reached the page.&#x22;,
    required: true,
  },
  timeOnPreviousPageMs: {
    type: &#x22;number?&#x22;,
    description: &#x22;Time spent on the previous page in milliseconds, when available.&#x22;,
  },
}"
/>

PaywallPageViewEvent [#paywallpageviewevent]

<TypeTable
  type="{
  event: {
    type: &#x22;\&#x22;paywallPageView\&#x22;&#x22;,
    description: &#x22;Identifies the multi-page paywall navigation event.&#x22;,
    required: true,
  },
  paywallInfo: {
    type: &#x22;PaywallInfo&#x22;,
    description: &#x22;Paywall metadata associated with the page view.&#x22;,
    required: true,
  },
  data: {
    type: &#x22;PageViewData&#x22;,
    description: &#x22;Details for the page the user navigated to.&#x22;,
    required: true,
  },
}"
/>

PaywallInfo [#paywallinfo]

<TypeTable
  type="{
  identifier: {
    type: &#x22;string&#x22;,
    description: &#x22;Paywall identifier from the Superwall dashboard.&#x22;,
    required: true,
  },
  name: {
    type: &#x22;string&#x22;,
    description: &#x22;Paywall name from the Superwall dashboard.&#x22;,
    required: true,
  },
  url: {
    type: &#x22;string&#x22;,
    description: &#x22;Hosted paywall URL.&#x22;,
    required: true,
  },
  presentationId: {
    type: &#x22;string?&#x22;,
    description: &#x22;Identifier used to correlate events within one paywall presentation lifecycle.&#x22;,
  },
  products: {
    type: &#x22;Product[]&#x22;,
    description: &#x22;Products available on the paywall.&#x22;,
    required: true,
  },
  productIds: {
    type: &#x22;string[]&#x22;,
    description: &#x22;Product identifiers available on the paywall.&#x22;,
    required: true,
  },
  presentedBy: {
    type: &#x22;string&#x22;,
    description: &#x22;Source that initiated the paywall presentation.&#x22;,
    required: true,
  },
  state: {
    type: &#x22;Record<string, any>&#x22;,
    description: &#x22;Paywall state captured on dismiss.&#x22;,
    required: true,
  },
  customerInfo: {
    type: &#x22;CustomerInfo?&#x22;,
    description: &#x22;Android 2.7.12+ snapshot of the user's subscription and entitlement state. Undefined on iOS.&#x22;,
  },
}"
/>

Product [#product]

<TypeTable
  type="{
  id: {
    type: &#x22;string&#x22;,
    description: &#x22;Product identifier.&#x22;,
    required: true,
  },
  name: {
    type: &#x22;string?&#x22;,
    description: &#x22;Product display name, when available.&#x22;,
  },
  entitlements: {
    type: &#x22;Entitlement[]&#x22;,
    description: &#x22;Entitlements granted by purchasing this product.&#x22;,
    required: true,
  },
  store: {
    type: &#x22;ProductStore?&#x22;,
    description: &#x22;Store that backs this product. Use `\&#x22;CUSTOM\&#x22;` to route purchases to your own purchase logic.&#x22;,
  },
  appStoreProduct: {
    type: &#x22;{ id: string }?&#x22;,
    description: &#x22;App Store product identifier data when `store` is `\&#x22;APP_STORE\&#x22;`.&#x22;,
  },
  stripeProduct: {
    type: &#x22;{ id: string; trialDays?: number }?&#x22;,
    description: &#x22;Stripe product identifier data when `store` is `\&#x22;STRIPE\&#x22;`.&#x22;,
  },
  paddleProduct: {
    type: &#x22;{ id: string }?&#x22;,
    description: &#x22;Paddle product identifier data when `store` is `\&#x22;PADDLE\&#x22;`.&#x22;,
  },
  customProduct: {
    type: &#x22;{ id: string }?&#x22;,
    description: &#x22;Custom product identifier data when `store` is `\&#x22;CUSTOM\&#x22;`.&#x22;,
  },
}"
/>

CustomerInfo (Android) [#customerinfo-android]

<TypeTable
  type="{
  userId: {
    type: &#x22;string&#x22;,
    description: &#x22;User ID at the time the snapshot was taken.&#x22;,
    required: true,
  },
  subscriptions: {
    type: &#x22;SubscriptionTransaction[]&#x22;,
    description: &#x22;Subscription transactions ordered by purchase date.&#x22;,
    required: true,
  },
  nonSubscriptions: {
    type: &#x22;NonSubscriptionTransaction[]&#x22;,
    description: &#x22;Non-subscription transactions ordered by purchase date.&#x22;,
    required: true,
  },
  entitlements: {
    type: &#x22;Entitlement[]&#x22;,
    description: &#x22;Entitlements available to the user.&#x22;,
    required: true,
  },
}"
/>

SubscriptionTransaction (Android) [#subscriptiontransaction-android]

<TypeTable
  type="{
  transactionId: {
    type: &#x22;string&#x22;,
    description: &#x22;Unique transaction identifier.&#x22;,
    required: true,
  },
  productId: {
    type: &#x22;string&#x22;,
    description: &#x22;Subscription product identifier.&#x22;,
    required: true,
  },
  purchaseDate: {
    type: &#x22;string&#x22;,
    description: &#x22;ISO-8601 purchase timestamp.&#x22;,
    required: true,
  },
  willRenew: {
    type: &#x22;boolean&#x22;,
    description: &#x22;Whether the subscription is set to renew.&#x22;,
    required: true,
  },
  isRevoked: {
    type: &#x22;boolean&#x22;,
    description: &#x22;Whether the transaction has been revoked.&#x22;,
    required: true,
  },
  isInGracePeriod: {
    type: &#x22;boolean&#x22;,
    description: &#x22;Whether the subscription is in a billing grace period.&#x22;,
    required: true,
  },
  isInBillingRetryPeriod: {
    type: &#x22;boolean&#x22;,
    description: &#x22;Whether the subscription is in a billing retry period.&#x22;,
    required: true,
  },
  isActive: {
    type: &#x22;boolean&#x22;,
    description: &#x22;Whether the subscription is currently active.&#x22;,
    required: true,
  },
  expirationDate: {
    type: &#x22;string | null&#x22;,
    description: &#x22;ISO-8601 expiration timestamp, or null for non-renewing subscriptions.&#x22;,
  },
  store: {
    type: &#x22;string&#x22;,
    description: &#x22;Store the transaction came from, such as `\&#x22;PLAY_STORE\&#x22;`.&#x22;,
    required: true,
  },
  offerType: {
    type: &#x22;\&#x22;trial\&#x22; | \&#x22;code\&#x22; | \&#x22;subscription\&#x22; | \&#x22;promotional\&#x22; | \&#x22;winback\&#x22; | \&#x22;revoked\&#x22;&#x22;,
    description: &#x22;Offer type applied to the subscription, when available.&#x22;,
  },
}"
/>

NonSubscriptionTransaction (Android) [#nonsubscriptiontransaction-android]

<TypeTable
  type="{
  transactionId: {
    type: &#x22;string&#x22;,
    description: &#x22;Unique transaction identifier.&#x22;,
    required: true,
  },
  productId: {
    type: &#x22;string&#x22;,
    description: &#x22;Product identifier.&#x22;,
    required: true,
  },
  purchaseDate: {
    type: &#x22;string&#x22;,
    description: &#x22;ISO-8601 purchase timestamp.&#x22;,
    required: true,
  },
  isConsumable: {
    type: &#x22;boolean&#x22;,
    description: &#x22;Whether the purchase is consumable.&#x22;,
    required: true,
  },
  isRevoked: {
    type: &#x22;boolean&#x22;,
    description: &#x22;Whether the transaction has been revoked.&#x22;,
    required: true,
  },
  store: {
    type: &#x22;string&#x22;,
    description: &#x22;Store the transaction came from, such as `\&#x22;PLAY_STORE\&#x22;`.&#x22;,
    required: true,
  },
}"
/>

Returned Values [#returned-values]

This hook does not return any values (`void`). Its purpose is to set up and tear down event listeners.

Example [#example]

```tsx
import { useSuperwallEvents } from "expo-superwall";

function EventLogger() {
  useSuperwallEvents({
    onSuperwallEvent: (eventInfo) => {
      console.log("Superwall Event:", eventInfo.event.event, eventInfo.params);
    },
    onSubscriptionStatusChange: (newStatus) => {
      console.log("Subscription Status Changed:", newStatus.status);
    },
    onPaywallPresent: (info) => {
      console.log("Paywall Presented (via useSuperwallEvents):", info.name);
    },
    onUserAttributesChange: (newAttributes) => {
      console.log("User Attributes Changed:", newAttributes);
      // Sync with analytics or update in-memory state
    },
  });
}
```