Rovenue SDKBeta
Guides

Identifying Users

Understand the two-identifier model and how to attach your backend user ID to the current install.

Every Rovenue install carries two identifiers: a permanent SDK-generated rovenueId and an optional appUserId that you supply when your user signs in. Purchases, virtual currencies, and entitlements always belong to the rovenueId; the appUserId is a label you attach so your backend can address the same subscriber regardless of which device they are on.

The identity model is optimistic: identify() updates local state instantly and fires a background network call to bind the IDs server-side. The user never waits for a round trip. See Methods — Identity.

Types on this page

type User = {
  rovenueId: string;        // permanent per-install id (prefix rov_); always present
  appUserId: string | null; // your backend user id; null until identify()
};
FieldTypeDescription
rovenueIdstringPermanent per-install identifier (prefix rov_); never changes for the lifetime of the install.
appUserIdstring | nullYour backend's user ID; null until identify() is called.

Swift and Kotlin mirror these with platform-idiomatic names (user.rovenueId / user.appUserId). See Types — User.


Identity lifecycle

Read the current user

currentUser() is a cache read — it never hits the network and returns instantly. Use it to check whether a user is already identified at startup, or use the React Native useCurrentUser() hook for reactive rendering.

import { Rovenue, useCurrentUser } from '@rovenue/react-native-sdk';

// Imperative cache read
const user = Rovenue.currentUser();
console.log(user.rovenueId);  // always present, e.g. "rov_01abc..."
console.log(user.appUserId);  // null until identify() has been called

// Reactive hook alternative — re-renders when identity changes
function Header() {
  const user = useCurrentUser();
  return <Text>{user?.appUserId ?? '(anonymous)'}</Text>;
}
let user = await Rovenue.shared.currentUser()
print(user.rovenueId)               // always present, e.g. "rov_01abc..."
print(user.appUserId ?? "(anonymous)") // nil until identify() has been called
val user = Rovenue.shared.currentUser()
println(user.rovenueId)                    // always present, e.g. "rov_01abc..."
println(user.appUserId ?: "(anonymous)")   // null until identify() has been called

Call identify() after sign-in

Call identify(appUserId, identityToken) immediately after your auth flow completes and you have a stable backend user ID. The identityToken comes from your backend: it mints one for the signed-in user with the secret key (POST /v1/identity-tokens) and hands it to the app. The token is valid for 15 minutes, so fetch a fresh one for each identify. See Identity verification.

The call is optimistic — local state updates immediately so entitlement reads are consistent without waiting for the server. In the background, Rovenue fires POST /v1/identify with the token to bind the appUserId to the current rovenueId. If that fails (offline, 5xx), the SDK retries with the same token. If the server refuses the token (IdentityTokenInvalid: expired, or minted for another user), the SDK drops that bind and throws; identify again with a fresh token.

If that appUserId already exists on another install, Rovenue automatically transfers that install's purchases and virtual-currency balances to this device. No extra call is required.

import { Rovenue } from '@rovenue/react-native-sdk';

// Call immediately after your auth flow resolves.
// Your backend minted identityToken for this user (POST /v1/identity-tokens).
await Rovenue.identify('user_abc123', identityToken);

// The local user now reflects the new appUserId
const user = Rovenue.currentUser();
console.log(user.appUserId); // "user_abc123"
// Call immediately after your auth flow resolves.
// Your backend minted identityToken for this user (POST /v1/identity-tokens).
try await Rovenue.shared.identify(appUserId: "user_abc123", identityToken: identityToken)

// The local user now reflects the new appUserId
let user = await Rovenue.shared.currentUser()
print(user.appUserId ?? "nil") // "user_abc123"
// Call immediately after your auth flow resolves (suspend function).
// Your backend minted identityToken for this user (POST /v1/identity-tokens).
Rovenue.shared.identify("user_abc123", identityToken)

// The local user now reflects the new appUserId
val user = Rovenue.shared.currentUser()
println(user.appUserId) // "user_abc123"

Use opaque, unguessable IDs for appUserId — never an email address, username, or any value a third party could predict. The identity token is what stops another device from binding to a user it only knows the ID of: mint it only for the user your backend has signed in, never for an ID the client asks for.

Call logOut() on sign-out

When your user signs out, call logOut(). This mints a fresh rovenueId for the install and clears appUserId and all scope-bound caches. The next user on a shared device starts with a clean slate and cannot inherit any prior entitlements or virtual-currency balances.

import { Rovenue } from '@rovenue/react-native-sdk';

// Call when your user signs out
await Rovenue.logOut();

const user = Rovenue.currentUser();
console.log(user.appUserId);  // null — fresh anonymous install
console.log(user.rovenueId);  // new rov_ id, different from the previous one
// Call when your user signs out
try await Rovenue.shared.logOut()

let user = await Rovenue.shared.currentUser()
print(user.appUserId ?? "nil")  // nil — fresh anonymous install
print(user.rovenueId)           // new rov_ id
// Call when your user signs out (suspend function)
Rovenue.shared.logOut()

val user = Rovenue.shared.currentUser()
println(user.appUserId)   // null — fresh anonymous install
println(user.rovenueId)   // new rov_ id

After logOut() the SDK emits an IdentityChanged change event. If you have listeners attached via addChangeListener, they fire automatically. See Reacting to changes.

Feature flags and experiment assignments are fetched per subscriber, so the SDK never serves one identity's values to another. On logOut(), on an identify() that links a different user, and when the server accepts the identify, the cached flags and assignments are dropped (memory and disk) and the new identity's are fetched at once. Until they arrive — immediately when online, for as long as the device is offline otherwise — every flag getter returns the fallback you pass and experiment() returns no assignment. A RemoteConfigChanged event fires when the old values are dropped and again when the new ones land. Identifying the same user again (for example at every launch) changes nothing and keeps the cache.


Reserved id prefixes

Some id shapes belong to the server. An app user id or a subscriber key that starts with one of these prefixes is refused with 400 VALIDATION_ERROR (the message says reserved prefix, for example Invalid subscriber key: reserved prefix, or appUserId uses a reserved prefix on identify):

PrefixWhat the server uses it for
srv_The Rovenue id it mints for an unclaimed buyer.
apple:, google:, stripe:Store anchors: the App Store, Google Play or Stripe purchase a buyer was first found by.
erased-import:The marker an erasure leaves for a customer you imported, so the same file cannot re-create them.
erased_The device id an erasure gives the erased subscriber, so the old device id is free for a new subscriber. Reserved since 2026-11-21: an app user id or a device id starting erased_ that was accepted before is now refused.

Every endpoint that takes a subscriber id from a client checks it before it reads or writes anything: /v1/config and its stream, /v1/placements, /v1/offerings, identify, receipts, events, sessions, experiments, attribution and the funnel claim. Accepting one would let anyone who learned a buyer's id (webhooks carry it) read that buyer's config or collect the purchase that later arrives for it.

The SDK sends the device's own rov_… id as its key, so in practice this only matters for identify(). Because identify() is optimistic, the call returns and the local state changes, but the server refuses to bind the id. If your own user ids can start with one of these prefixes, add a prefix of your own before you pass them in.


How store notifications find the user

The App Store and Google Play tell Rovenue about a purchase on their own, often before your app has posted the receipt. To route that notification to the right subscriber, the SDK stamps every purchase with a value derived from the current rovenueId, and the server derives the same value:

  • Apple: appAccountToken is a lowercase UUIDv5 of the rovenueId.
  • Google Play: obfuscatedAccountId is the lowercase hex SHA-256 of a fixed prefix plus the rovenueId. It carries no personal data.

Rovenue binds both values to the subscriber on every app launch (/v1/config) and on identify(), before any paywall is shown. A notification that arrives before the receipt is therefore routed by that binding: first the token or account id, then the purchase it already knows, and only then an unclaimed buyer: an anonymous subscriber Rovenue creates on its own, with a server-minted srv_… id and no app user id. The buyer is found again by its store anchor (apple:<originalTransactionId> or google:<purchaseToken prefix>), which Rovenue records as one of the buyer's ids, not as its id. The value is a routing hint, never an identity key: it identifies no one on its own.

  • identify() keeps the same value; the binding moves with the merge.
  • logOut() mints a new rovenueId, so a new value.
  • A notification that carries a value Rovenue has no binding for, and no purchase yet, is retried once after 60 seconds before an unclaimed buyer is created, so the receipt or the next launch can land first.
  • Purchases with no value at all (offer-code redemptions, App Store promoted purchases before first launch, a device that never reached the API) still create the unclaimed buyer.
  • When the app later posts the receipt, the buyer is merged into the app's subscriber: its purchases, access and virtual-currency balances move across and the buyer is retired. The merge is recorded like every other one: an audit-log entry, a subscriber.merged webhook with reason RECEIPT_MERGE, and an entry in the customer's Activity in the dashboard. The buyer's ids (srv_…, the store anchor) keep resolving to the survivor.
  • Stripe and web checkout are unaffected: the server stamps the app user id before payment. A web funnel purchase made before the app exists is held the same way and claimed in the app; see Claiming the result.

Android apps that run Play Billing themselves have no public getter for the Play value; only purchase() and reconcilePurchases() attach it. Their purchases fall back to the receipt merge above. getAppAccountToken() returns the Apple value.


Backend-driven consolidation

For authoritative, bulk, or programmatic merging — for example, importing subscribers from another platform or resolving a support-driven account merge — your backend can call the transfer endpoint directly using your secret API key:

POST /v1/subscribers/transfer
Authorization: Bearer <secret-api-key>
Content-Type: application/json

{
  "fromAppUserId": "anon-device-123",
  "toAppUserId":   "user_42"
}

This call is server-to-server only. It gives you full control over which subscriber "wins" and is the recommended path for bulk migrations or cases where the client-side auto-transfer behaviour is insufficient.

Every asset of fromAppUserId (purchases, access, virtual-currency balances) moves to toAppUserId, and the source is retired. fromAppUserId may also be any other current id of the customer (a device Rovenue id, a store identifier such as stripe:<customer id>); an app user id a merge already retired answers 400 already transferred. toAppUserId may also be a Rovenue id. Every merge is recorded once in the audit log and sent as a subscriber.merged webhook. The responses to handle:

Statuserror.codeMeaningWhat to do
200—The merge happened.Nothing.
404SUBSCRIBER_NOT_FOUND, error.details.side: "to"The target has no subscriber yet: that user was never identified on any device.Create the target (call identify() on a device) and retry.
404SUBSCRIBER_NOT_FOUND, error.details.side: "from"No subscriber ever carried the source id in this project.Check the id. There is nothing to transfer under it.
400VALIDATION_ERRORThe body is malformed, the two ids are equal, or the source or target was already merged into another subscriber. A source the client's identify() already merged lands here, with the message … has already been transferred.Fix the request. An already-merged source needs nothing more. Do not retry it unchanged.
409CONFLICTOne of the two subscribers changed while the merge was starting: its id moved to another row, or it was merged concurrently.Retry. If it was merged away, the retry answers 400 already transferred.
409UNCLAIMED_BUYER_TARGETThe target is a buyer Rovenue recorded server-side (a srv_… id) that no app has claimed yet. An unclaimed buyer never absorbs another customer. Nothing was moved.Not retryable: the same call answers the same way. Swap the sides and merge the buyer into the customer's account.
503DATABASE_UNAVAILABLE and other infra codesA temporary outage.Retry after the Retry-After header.
404 response
{
  "error": {
    "code": "SUBSCRIBER_NOT_FOUND",
    "message": "Target subscriber 'user_42' not found",
    "details": { "side": "to" }
  }
}

Never put your secret API key (rov_sk_…) in the app binary. The transfer endpoint is a server-to-server call only. Expose a lightweight endpoint in your own backend that verifies the user session and then calls Rovenue on their behalf.


On this page