
RevenueCat Subscriber Attributes for Affiliate Tracking
Store the affiliate id as a RevenueCat subscriber attribute, set it before the purchase, and it arrives inside every webhook event under subscriber_attributes. Set it after the purchase and the INITIAL_PURCHASE payload goes out without it, permanently. That ordering detail is the most common integration mistake we see in RevenueCat affiliate setups, and it fails silently: the click is recorded, the purchase is recorded, nothing connects them.
This is for the engineer who has an affiliate id on first open and needs it to reach the webhook. Swift, Kotlin, TypeScript and Dart calls are below.
#What a RevenueCat subscriber attribute is
A RevenueCat subscriber attribute is a key and value pair on a customer record, which RevenueCat describes as "storing additional, structured information on a customer that can be used elsewhere in the system" (customer attributes, verified 2026-09-12). Attributes travel with the customer into webhook events.
Two kinds exist. Reserved attributes begin with $ and RevenueCat owns that namespace: $email, $displayName, $idfa, $appsflyerId and a long tail of integration ids. Custom attributes are yours, and the docs state their keys "cannot start with $", so affiliate_id is legal and $affiliate_id is not.
Delivery is what matters for commissions. RevenueCat's webhook event fields reference lists subscriber_attributes among the top level fields, as a map from name to an object with value and updated_at_ms:
"subscriber_attributes": {
"affiliate_id": {
"updated_at_ms": 1757635200000,
"value": "aff_9f2c41"
}
}updated_at_ms is the only timestamp telling you whether the attribute existed before the purchase or was bolted on afterwards. We use it as a debugging signal, never as a matching key. Read the attribute, but do not make it the primary join: the field reference marks subscriber_attributes as present only sometimes, and a payment path built on an optional field drops money on a quiet Tuesday.
#Why the affiliate id belongs in a subscriber attribute
A subscriber attribute is the only place an affiliate id reaches your commission ledger without your backend being reachable at purchase time. RevenueCat stores it on the customer and replays it on the event. Every other option needs a live server or a second lookup.
The attribute wins on durability, not elegance: the alternatives fail in ways you cannot see from the payload.
| Where the affiliate id lives | What it gives you | Failure mode |
|---|---|---|
| Subscriber attribute | On the event itself, no lookup | Silently absent if set after the purchase |
| `app_user_id` | Always present, impossible to lose | Locks marketing data into identity; 100 character cap |
| Backend join on user id | Full control, id stays private | Needs the attribution write to land before the event |
| Deferred deep link only | No SDK work at purchase time | Nothing carries it into the revenue event |
We run the third row as the primary path. MyAppAffiliate's RevenueCat ingest joins on app_user_id, because that field is mandatory and the attribute is not. The attribute is the corroborating copy: when a creator was not paid, its presence on the event separates an app ordering fault from a missing attribution write.
Two paths is belt and braces. Money paths earn that.
#The ordering that has to be right
Five calls, in this order: capture the attribution on first open, identify the user in your attribution SDK, call RevenueCat logIn() with the identical id, set the affiliate_id attribute, then let the paywall run. RevenueCat syncs attributes when a purchase is made, so one that exists beforehand rides out on the purchase event.
- Capture the attribution on first open. A Universal Link, an App Link, or a typed referral code.
- Identify the user with your own id. A UUID from your backend, the same string you hand RevenueCat.
- Call RevenueCat
logIn(userId)with the byte-identical id. Not lowercased, not trimmed, not a display name. - Set the attribute. One
setAttributescall withaffiliate_id. - Present the paywall. Only now.
Nobody catches this in code review. The app compiles, the purchase succeeds, the user gets their entitlement. In the MyAppAffiliate dashboard the click is there with a timestamp, the RevenueCat event is there with the right price and product, and the affiliate row reads one click, zero conversions.
We see it more than every other RevenueCat integration bug combined, for a structural reason: most apps set attributes in a profile screen or an analytics helper that runs after onboarding, while the paywall runs during onboarding. Right file, wrong lifecycle. Pull the raw event:
// The purchase event you want
event.subscriber_attributes?.affiliate_id?.value // "aff_9f2c41"
// The purchase event you get when the attribute is set too late
event.subscriber_attributes?.affiliate_id // undefinedundefined on INITIAL_PURCHASE but populated on the first RENEWAL for the same app_user_id means ordering is the bug. Our position: put setAttributes in the function that configures RevenueCat, immediately after logIn, never in a screen. Lifecycle proximity beats logical grouping. Separately, what each event does to the ledger.
#Setting the attribute on iOS, Android, React Native and Flutter
RevenueCat exposes one attribute call per platform and only iOS differs: Swift routes through Purchases.shared.attribution.setAttributes, while Kotlin, TypeScript and Dart call setAttributes on the Purchases object. The key is affiliate_id on all four, byte-identical to what your ingest reads.
Pick your row and the whole change is a nil check and a call.
| Platform | RevenueCat call | MyAppAffiliate SDK call | Documented at |
|---|---|---|---|
| iOS (Swift) | `Purchases.shared.attribution.setAttributes` | `MyAppAffiliate.attributedAffiliateId()` | [iOS SDK](https://docs.myappaffiliate.com/sdk-ios) |
| Android (Kotlin) | `Purchases.sharedInstance.setAttributes` | `MyAppAffiliate.attributedAffiliateId()` | [Android SDK](https://docs.myappaffiliate.com/sdk-android) |
| React Native | `Purchases.setAttributes` | `myAppAffiliate.attributedAffiliateId()` | [React Native SDK](https://docs.myappaffiliate.com/sdk-react-native) |
| Flutter | `Purchases.setAttributes` | `MyAppAffiliate.attributedAffiliateId()` | [Flutter SDK](https://docs.myappaffiliate.com/sdk-flutter) |
On iOS, guard on the optional. Nothing happens without attribution, which is the common case for organic installs:
import RevenueCat
if let affiliateId = MyAppAffiliate.attributedAffiliateId() {
Purchases.shared.attribution.setAttributes(["affiliate_id": affiliateId])
}RevenueCat buffers the value and flushes it on its next sync.
Kotlin, same shape:
import com.revenuecat.purchases.Purchases
MyAppAffiliate.attributedAffiliateId()?.let { aff ->
Purchases.sharedInstance.setAttributes(mapOf("affiliate_id" to aff))
}React Native, where the getter is async and the await matters more than it looks:
import Purchases from "react-native-purchases";
const aff = await myAppAffiliate.attributedAffiliateId();
if (aff) await Purchases.setAttributes({ affiliate_id: aff });Flutter:
import 'package:purchases_flutter/purchases_flutter.dart';
final aff = await MyAppAffiliate.attributedAffiliateId();
if (aff != null) {
await Purchases.setAttributes({'affiliate_id': aff});
}In all four, a missing affiliate id is a no-op, not a thrown error. Deliberate: an attribution SDK that can break a paywall gets deleted.
MyAppAffiliate is an affiliate and creator attribution platform for subscription mobile apps and SaaS. It tracks affiliate links and codes from click to install, subscription, renewal and refund through RevenueCat, Adapty, Superwall, Stripe and Paddle webhooks, calculates commissions, and pays creators, with flat pricing and no percentage of revenue. attributedAffiliateId() exists so the RevenueCat side stays one line. The link service, claim token and webhook endpoint are in the full setup.
#What anonymous users and alias merges do to the join
RevenueCat generates "a new random App User ID (prefixed with $RCAnonymousID:)" when your app configures the SDK without one (identifying customers, verified 2026-09-12). A purchase before logIn() carries that anonymous id, so the webhook does not match the id your backend attributed, even with the attribute present.
Read RevenueCat's merge table before you design around this. Anonymous to a custom id merges the customer info, unless that id already has an anonymous alias, in which case the current user is logged out instead. Non-anonymous to anything never merges.
After a merge, the docs say there will be "only one App User ID within the original_app_user_id field" while the others sit in an aliases array. The identity information is on the payload; look past app_user_id.
We have a known gap here. MyAppAffiliate's ingest does not consume SUBSCRIBER_ALIAS or TRANSFER today, so an anonymous purchase followed by a login does not self-heal. Our matrix test for it is checked in as a failing expectation named KNOWN GAP, because a documented hole in CI beats a surprise in a payout run. Consuming TRANSFER and aliases is planned.
The workaround is one line: call identify() again with the real user id after login. That triggers our backfill, which re-runs attribution over events already stored under that id and creates the missed commission. We built it after a test showed a late identify() dropping a commission while the webhook returned 200.
Treat logIn() before the paywall as a hard requirement, not a best practice. Every recovery path after that point costs someone an afternoon.
#Should you encode the affiliate id in app_user_id instead?
No, app_user_id is the wrong home for an affiliate id, except in one narrow case. RevenueCat treats app_user_id as identity: it drives aliasing, merges and entitlement lookups, and the docs cap it at 100 characters, block placeholder strings including null, none, guest and anonymous, and reject any id containing /. Packing marketing data into an identity key means changing identity when the marketing data changes.
The temptation comes from the right instinct. app_user_id is mandatory on every event and subscriber_attributes is not, so user_9f2c41:aff_lumi looks like a way to make the affiliate id as reliable as identity.
Four things go wrong. The id becomes guessable, which RevenueCat warns against when it says "Don't set emails as App User IDs"; a composite key carrying a public creator code fails the same test. Reassigning a user to a different affiliate needs a logIn() and possibly a merge. Your database and RevenueCat disagree about the user id. And the 100 character ceiling matters once someone appends a campaign.
The case we would accept: a single-purpose build with one hardcoded partner, no login, and a lifespan measured in weeks. Even there, set the attribute too, because that is what the ledger reads.
Already shipped a composite id? Do not rewrite it. Set the attribute going forward and parse legacy ids behind a version marker. Migrating identity strings on a live subscription base is how entitlements get lost.
#The limits RevenueCat enforces on attribute values
RevenueCat documents "up to 50 unique custom attributes per subscriber, with key names up to 40 characters long and values up to 500 characters long" (customer attributes, verified 2026-09-12). Keys beginning with $ are reserved. Any attribute is cleared by passing null or an empty string as the value.
An affiliate id uses a fraction of that. affiliate_id is 12 of the 40 key characters, and a UUID or short creator code sits well under 500. The limits bite only when someone serializes a whole attribution context into one value. Four hygiene rules we hold to:
- One canonical key across every platform.
affiliate_id, lowercase, underscore. A codebase withaffiliate_idon iOS andaffiliateIdon Android produces two attributes and one working platform. - Store the id, not the context. Campaign, medium and link id belong in your attribution record. The attribute is a pointer.
- Nothing personal in the value. No email, no name, no device identifier. RevenueCat reserves keys for identifiers that need special handling; an affiliate id is not one.
- Clear deliberately, never by accident. An empty string deletes the attribute, so a getter returning
""instead ofnilon a cold start wipes a good value.
That fourth one is the only limit-related bug we have chased, and it came from a wrapper coalescing nil to "" for logging. Never let an attribute value pass through a formatting helper.
#How to verify it end to end before you ship
Four checks catch every ordering bug: a sandbox purchase, the RevenueCat customer record, the raw webhook payload, and a local replay. Run them in that order, because each narrows the fault. RevenueCat expects a 200 and retries up to 5 times, at 5, 10, 20, 40 and 80 minutes.
- Make a sandbox purchase after a fresh install. Delete the app first. A reinstall keeps the attribute on the customer record and hides the bug you are hunting.
- Read the attributes panel on the RevenueCat customer. If
affiliate_idis absent, the SDK call never ran. If present, check whether its timestamp precedes the transaction. - Read the raw
INITIAL_PURCHASEpayload, not a parsed log line. Checkevent.subscriber_attributes.affiliate_id.value, thenevent.app_user_idagainst the id you passedidentify(). A trailing space survives JSON and breaks the join. - Replay the payload against your local endpoint with your webhook secret in the
Authorizationheader, per the webhook setup. This is where you learn whether the commission gets created.
For MyAppAffiliate apps, step 4 has a shortcut that rehearses the loop against the live database with no device:
pnpm --filter @maa/api smokeStep 1 is the one people skip and the one that matters. Attributes persist on the customer record, so a developer testing on their own phone for the fifth time sees affiliate_id on every event, wherever setAttributes sits. We have watched an ordering bug pass manual QA that way and surface only when real first installs converted with empty payloads. Then assert on it: a test that fails when affiliate_id is missing from an INITIAL_PURCHASE fixture turns a silent revenue bug into a red build.
Do RevenueCat custom attributes appear in webhooks?
Yes. RevenueCat's webhook fields reference lists `subscriber_attributes` as a map of attribute name to an object holding `value` and `updated_at_ms`. Custom keys sit alongside reserved `$` keys. The field is documented as present only sometimes, so treat a missing map as normal and join on `app_user_id`.
What happens if I set the attribute after the purchase?
RevenueCat has already sent the purchase event and does not resend it. Your `INITIAL_PURCHASE` payload carries no `affiliate_id`, and the value first appears on the next renewal. In a dashboard that reads as a recorded click, a recorded purchase, no commission.
Should the affiliate id go in app_user_id instead?
No, in almost every case. RevenueCat treats the App User ID as identity: it drives aliasing, merges and entitlement lookups, caps at 100 characters, and blocks a list of placeholder strings. Changing it later means a login and a possible merge. Use an attribute.
How do anonymous purchases affect attribution?
A purchase made before `logIn` arrives under RevenueCat's `$RCAnonymousID` value, so it never matches the id your backend attributed. RevenueCat merges the identities on login, but the event has already left. Calling `identify()` again with the real id recovers the commission today.
Is there a length limit on attribute values?
Yes. RevenueCat documents up to 50 unique custom attributes per subscriber, key names up to 40 characters and values up to 500 characters. Keys beginning with a dollar sign are reserved. An affiliate id fits easily, so we store the raw id alone.
#Move the setAttributes call today
Open the file where you call RevenueCat logIn() and put the setAttributes call on the line after it. That is the whole fix, and it takes longer to open the file than to make the change. Then run one sandbox purchase from a fresh install and read subscriber_attributes.affiliate_id in the raw payload. Snippets per platform are in the iOS SDK reference.