Skip to main content
Solved

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


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?

5 replies

hussain
RevenueCat Staff
Forum|alt.badge.img+2
  • RevenueCat Staff
  • 23 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


Forum|alt.badge.img

❓ Thanks for your previous answer! I have a follow-up question about RCAnonymousID and App Store promo codes

 

Thanks for your previous answer! I’d like to clarify one more thing related to anonymous users and promo code redemptions via the App Store.

 

🔹 Scenario:

1. The user has never opened the app before — the RevenueCat SDK has not been initialized.

2. They redeem a promo code via the App Store.

3. RevenueCat creates an anonymous user (e.g. RCAnonymousID:abc123) and sends a webhook — I receive and store this ID on my backend.

4. Later, the user opens the app for the first time and I call:

await Purchases.configure(PurchasesConfiguration('sdk_key'));

final info = await Purchases.getCustomerInfo();

 

❓ My questions:

• Will the originalAppUserId from the SDK match the one from the webhook (RCAnonymousID:abc123)?

• Or will the SDK generate a new anonymous ID, unrelated to the one used during the promo redemption?

• What’s the correct way to ensure that the promo subscription gets linked to the same user when they eventually open the app?

 

Thanks again for your help! 🙏


hussain
RevenueCat Staff
Forum|alt.badge.img+2
  • RevenueCat Staff
  • 23 replies
  • May 5, 2025

Hi Emmanuil,

Great follow-up — and thanks for the detailed scenario!

To clarify: unfortunately, the approach you described won’t work as expected. When the user opens the app for the first time and the RevenueCat SDK is initialized, it will generate a new anonymous user ID (e.g., a fresh $RCAnonymousID:def456). This new ID will not match the original anonymous ID ($RCAnonymousID:abc123) that was created when the promo code was redeemed via the App Store — meaning the SDK won’t be aware of the original purchase made under that previous anonymous ID.

Because of this, calling getCustomerInfo() right after configuring the SDK will return data for this new anonymous user, and not the one linked to the promo code redemption. As a result, the subscription won’t be visible in the app until the correct user ID is linked.

The best workaround remains the one I shared earlier

There’s no truly elegant way to solve this due to platform limitations, but if it fits your use case, I strongly recommend exploring offer codes instead of promo codes. Offer codes are typically redeemed within the app, after login, which allows RevenueCat to immediately associate the purchase with a known user — making the entire flow far more robust and reliable.

Hope this helps!

Best,

Hussain


Forum|alt.badge.img

Hi Hussain,

Thanks for the clarification — things are much clearer now.

I’d really appreciate it if you could walk me through the setup process for offer codes, step by step. I’ve looked through the documentation, but I’m still a bit confused about how exactly they work in practice — especially compared to promo codes and how they’re meant to be redeemed inside the app.

Thanks again for your help!

Best regards,
Emmanuil


hussain
RevenueCat Staff
Forum|alt.badge.img+2
  • RevenueCat Staff
  • 23 replies
  • May 12, 2025

Hi Emmanuil,

We actually have an excellent blog post that walks through the entire process of creating and tracking offer codes in iOS apps:
👉 Create and Track Offer Codes in Your iOS App

This guide covers everything from setting up offer codes in App Store Connect to handling redemption flows in-app. It should give you a clear, step-by-step view of how offer codes work and how they differ from promo codes.

Hope this helps!

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