Skip to main content
Solved

Handling Anonymous Promo Code Subscriptions with RevenueCat: Associating Webhooks with Logged-In Users in Flutter

  • April 16, 2025
  • 1 reply
  • 55 views

Forum|alt.badge.img

Hi! I have a Flutter app using RevenueCat for subscriptions.

When a user activates a promo code via the App Store (outside the app), RevenueCat sends a webhook with an anonymous app_user_id (e.g., RCAnonymousID:abc123).

The problem is that my backend expects a known user_id to associate the subscription with a user. Since the user hasn’t logged in yet, there’s no way to identify them based on this anonymous ID, and the webhook ends up being ignored.

Later, when the user logs in to the app, I call:

await Purchases.logIn(customUserId);

But by that time, the webhook has already been processed (or missed), and there’s no connection between the anonymous ID and the logged-in user.

 

What I want:

  • To be able to process the first webhook, even if the subscription was activated anonymously (via promo code).

My questions:

  • What is the correct way to associate an anonymous RevenueCat ID with a custom user ID?

  • How can I reliably process the first webhook and link it to the right user?

  • Is there a way to track or reprocess such webhooks after login?

Thanks a lot for your help!

Best answer by hussain

Hi Emmanuil,

Thanks for reaching out — happy to help!

You're absolutely right that when a user redeems a promo code outside the app (via the App Store), RevenueCat receives the subscription event and it is tied to an anonymous app_user_id (like $RCAnonymousID:abc123). Since the user hasn’t logged into your app yet, it’s tricky to associate that webhook with a specific user on your backend.

That said, here's a workaround you can consider:

  1. Cache the webhook on your backend when it's received. Since it’s anonymous, you won’t be able to process it just yet, but you can store it temporarily.

  2. Once the user installs the app and logs in, call:

    await Purchases.logIn(customUserId); This will associate the current anonymous user with your custom user_id.

  3. Immediately after logging in, call:

    await Purchases.syncPurchases();

    This triggers a sync of any purchases that were made while the user was anonymous, ensuring they’re now attached to the correct customer profile.

  4. At this point, your user will have a unified profile in RevenueCat (including the original anonymous ID), and you can process the cached webhook by attributing it to this user based on the now-linked app_user_ids.

This approach isn't ideal, but it's currently the best workaround given the constraints.

Furthermore, due to limitations in the information Apple provides, RevenueCat cannot distinguish promo code purchases from regular purchases — they’re treated the same in our system.

As an alternative, you might want to consider using offer codes instead of promo codes. Offer codes are redeemed within the app, typically after login, which means RevenueCat can attribute the purchase directly to the logged-in user— making the whole flow much cleaner and reliable.

Hope this helps! Let me know if you have any follow-up questions.

Best,

Hussain

View original
Did this post help you find an answer to your question?

1 reply

hussain
RevenueCat Staff
Forum|alt.badge.img+1
  • RevenueCat Staff
  • 17 replies
  • Answer
  • April 18, 2025

Hi Emmanuil,

Thanks for reaching out — happy to help!

You're absolutely right that when a user redeems a promo code outside the app (via the App Store), RevenueCat receives the subscription event and it is tied to an anonymous app_user_id (like $RCAnonymousID:abc123). Since the user hasn’t logged into your app yet, it’s tricky to associate that webhook with a specific user on your backend.

That said, here's a workaround you can consider:

  1. Cache the webhook on your backend when it's received. Since it’s anonymous, you won’t be able to process it just yet, but you can store it temporarily.

  2. Once the user installs the app and logs in, call:

    await Purchases.logIn(customUserId); This will associate the current anonymous user with your custom user_id.

  3. Immediately after logging in, call:

    await Purchases.syncPurchases();

    This triggers a sync of any purchases that were made while the user was anonymous, ensuring they’re now attached to the correct customer profile.

  4. At this point, your user will have a unified profile in RevenueCat (including the original anonymous ID), and you can process the cached webhook by attributing it to this user based on the now-linked app_user_ids.

This approach isn't ideal, but it's currently the best workaround given the constraints.

Furthermore, due to limitations in the information Apple provides, RevenueCat cannot distinguish promo code purchases from regular purchases — they’re treated the same in our system.

As an alternative, you might want to consider using offer codes instead of promo codes. Offer codes are redeemed within the app, typically after login, which means RevenueCat can attribute the purchase directly to the logged-in user— making the whole flow much cleaner and reliable.

Hope this helps! Let me know if you have any follow-up questions.

Best,

Hussain


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings