Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,64 @@ When a user opens your app with the new Superwall SDK, their active subscription
| A/B test history and experiment data | ❌ No |
| Custom user attributes from previous SDK | ❌ No - must be re-set via Superwall SDK |

## Re-setting Custom User Attributes

Superwall reads subscription state directly from Apple and Google, so transaction history does not need to be migrated. Your own user metadata can be added as user attributes. The original transaction ID is a stable key that bridges a returning subscriber back to their record in your backend.

The flow:

<Steps>

### Read the original transaction ID on device

On iOS, use StoreKit 2's `Transaction.currentEntitlements` and read `transaction.originalID`. On Android, use the Play Billing `purchaseToken`.

```swift
import StoreKit

func fetchOriginalTransactionID() async -> String? {
for await result in Transaction.currentEntitlements {
guard case .verified(let transaction) = result else { continue }
return String(transaction.originalID)
}
return nil
}
```

### Look up the user in your backend

Send the original transaction ID to your backend, which returns a stable `userId` and any metadata you want exposed to Superwall (plan tier, signup date, referrer, etc.).

### Identify, then set attributes

Call `identify` first so the attributes attach to the right user.

```swift
Superwall.shared.identify(userId: userId)
Superwall.shared.setUserAttributes([
"plan_tier": "pro",
"signup_date": "2024-01-15",
"referrer": "appstore_search"
])
```

</Steps>

<Note>
`setUserAttributes` merges with existing attributes rather than replacing them. Pass `nil` for a key to remove it.
</Note>

<Warning>
A few things to watch for:

- Always call `identify` before `setUserAttributes`, otherwise attributes attach to the anonymous user.
- On a fresh install before a restore, `currentEntitlements` may be empty.
- Sandbox and production original transaction IDs differ.
- With Family Sharing, the original transaction ID belongs to the original purchaser, not the family member.
</Warning>

Run this on app launch (after StoreKit hydrates), after a successful purchase, and after a restore. It is safe to call every launch since `identify` is idempotent.

## Migration Steps

1. Remove your current subscription SDK from your project
Expand Down
Loading