Anonymous user
Why anonymous ?
If your app can be used without requiring the user to register (like news app) and you want to offer purchases to unlock content, Apple will refuse that you force the user to register to subscribe.
In that case you will have to handle anonymous purchases (aka unregistered user purchases).
Purchasely helps you combine the power of Server to Server notifications (S2S) with anonymous purchases.
Consumable and non-consumables won't be transfered from an anonymous user to a authentified user
Handling anonymous purchasing
To handle anonymous users, Purchasely SDK automatically generates an anonymous_user_id for the user. This anonymous_id remains consistent as long as the user keeps the app on its device.

The anonymous user purchase a product → Purchasely SDK generates an
anonymous_user_idOnce the store receipt validated, an event carrying this
anonymous_user_idis sent on the webhookThe association between the
anonymous_user_idand the Product & Plan purchased must be stored in the developer database.The app can use a dedicated method of the SDK to get the
anonymous_user_idfrom the SDK and check with the database that the user can access the content / service.
1. Proceeding with an anonymous Purchase
If no UserIdhas been attached to the user by the app to Purchasely SDK, the user will be treated as an anonymous user.
When an anonymous user makes an In-App Purchase, the platform will automatically associate it to the anonymous_user_idfor the user. This anonymous_user_idis tied to this particular device and remains consistent as long as the app remains installed on the device and will be the key for your backend to authorize the purchase on the device.
2. Getting the user anonymous_id from the webhook
When an event occurs on a subscription made by an anonymous user, the webhook message carries the user anonymous_user_idgenerated by Purchasely.
3. Attaching the purchase to the anonymous user
Purchases and corresponding entitlements must be attached to the anonymous user and stored in your database, using the anonymous_user_id.
Every subsequent purchase or event for this particular user will carry the same anonymous_user_id. In other words, when a particular event (renewal / cancellation / expiration etc...) happens on an anonymous user subscription, it will carry the same anonymous_user_id.
4. Getting user entitlements & anonymous_id in the app
Entitlements are managed by the developer backend and directly attached to the anonymous_user_id. The app can retrieve the anonymous_user_id from the SDK using the following method :
To ease customer support, we advise you to display both anonymous_user_id and user_id inside your app (e.g. in the section "My Subscriptions", in the settings or in the contact-us mail). This will help you identify the user in the Purchasely Console or in your own logs.
Authentication of an anonymous user
To authenticate an anonymous user, just set the appUserId. If your user had a subscription we will transfer it to the connected user. That implies sending events to your backend and wait for it to confirm before you try to refresh your entitlements. This is why you have a closure that passes a boolean telling you if the entitlements of the logged in user should be refreshed.
Do not forget to call Purchasely.userLogin("YOUR_USER_ID")before returning the result to Purchasely to properly update the presentation without the sign-in button.
Once the user has been connected all the purchased subscriptions are transferred from the anonymous user, to the connected user. User entitlements shall thus be refreshed by the App.
The Webhook will receive 2 Transactional events, a ACTIVATE for the connected user and a DEACTIVATE for the anonymous user. The webhook and integrations you activated will also receive 2 events, a SUBSCRIPTION_RECEIVEDfor the connected user and a SUBSCRIPTION_TRANSFERREDfor the anonymous user.
Intercept paywall actions

Every presentation, has a Already subscribed? Sign-in button to let your customers connect to unlock a feature / access a content.
This button is displayed if you did not set a user id with Purchasely.userLogin() see SDK configuration for more information.
To intercept this event, you can setup a global handler that passes you the source paywall controller / fragment above which to display login.
IF the user signs in AND has a subscription, you can dismiss the paywall controller
IF the user signs in AND doesn't have a subscription, dismiss your login controller and notify the SDK by calling the
isLoggedInclosure withtrueIF the user cancels sign-in, dismiss your login controller and notify the SDK by calling the
isLoggedInclosure withfalse
Do not forget to call Purchasely.userLogin("YOUR_USER_ID")before returning the result to Purchasely to properly update the presentation without the sign-in button.
Last updated
Was this helpful?