Reacting to Changes
Subscribe to real-time SDK events for entitlement, identity, and credit updates.
The SDK emits a ChangeEvent whenever its internal state changes — after a purchase, an identity update, or a virtual-currency balance change. Subscribe to drive UI updates without polling.
In React Native you rarely need the imperative listener directly — the hooks (useEntitlement, useEntitlements, useCurrentUser, useVirtualCurrencies, useVirtualCurrency) subscribe and unsubscribe automatically. Use the imperative API for non-component code or for Swift/Kotlin.
Types on this page
ChangeEvent is an enum whose value tells you which cache to re-read. Full definition: Types → ChangeEvent.
// React Native — string union
type ChangeEvent =
| 'ENTITLEMENTS_CHANGED'
| 'IDENTITY_CHANGED'
| 'VIRTUAL_CURRENCIES_CHANGED'
| 'REMOTE_CONFIG_CHANGED';On Swift the change stream is AsyncStream<ChangeEvent> and the cases are .entitlementsChanged, .identityChanged, .virtualCurrenciesChanged, .remoteConfigChanged.
On Kotlin the change stream is SharedFlow<ChangeEvent> and the constants are ChangeEvent.ENTITLEMENTS_CHANGED, ChangeEvent.IDENTITY_CHANGED, ChangeEvent.VIRTUAL_CURRENCIES_CHANGED, ChangeEvent.REMOTE_CONFIG_CHANGED.
| Event value | When it fires |
|---|---|
ENTITLEMENTS_CHANGED | After the entitlement cache is refreshed — e.g. after a purchase, refreshEntitlements(), or a foreground sync. |
IDENTITY_CHANGED | After logOut() resets the user, or after identify() once the server bind and an entitlements refresh attempt have run: the refresh fires ENTITLEMENTS_CHANGED first when it lands, so re-reading the cache here shows the identified user's access, and identify() resolves after that one entitlements fetch. If the fetch fails, the event still fires over what is cached and the background sync fills it. When the bind is not delivered (offline, server error, refused), it fires right after the local link, and the cache fills once the bind is retried and lands. Virtual-currency balances refresh afterwards, on their own event. |
VIRTUAL_CURRENCIES_CHANGED | After refreshVirtualCurrencies() or a server-side grant/spend that updates the cache. |
REMOTE_CONFIG_CHANGED | After the remote-config cache is refreshed — e.g. after refreshRemoteConfig() or a foreground sync. |
Subscribe to the change stream
import { Rovenue } from '@rovenue/react-native-sdk';
// addChangeListener returns an unsubscribe function — call it to clean up
const unsub = Rovenue.addChangeListener((event) => {
switch (event) {
case 'ENTITLEMENTS_CHANGED':
console.log('Entitlements updated — re-check access');
break;
case 'IDENTITY_CHANGED':
console.log('Identity changed — re-read current user');
break;
case 'VIRTUAL_CURRENCIES_CHANGED':
console.log('Virtual-currency balances changed — re-read balances');
break;
case 'REMOTE_CONFIG_CHANGED':
console.log('Remote config changed — re-read values');
break;
}
});In React components, use the hooks instead — they handle subscription lifecycle automatically:
import {
useEntitlement,
useEntitlements,
useCurrentUser,
useVirtualCurrencies,
useVirtualCurrency,
} from '@rovenue/react-native-sdk';
function ProBadge() {
const pro = useEntitlement('pro'); // re-renders on ENTITLEMENTS_CHANGED
return pro?.isActive ? <Crown /> : null;
}import Rovenue
// Rovenue.shared.changes is an AsyncStream<ChangeEvent>
// Consume it inside a Task that you own so you can cancel it later
let task = Task {
for await event in Rovenue.shared.changes {
switch event {
case .entitlementsChanged:
print("Entitlements updated — re-check access")
case .identityChanged:
print("Identity changed — re-read current user")
case .virtualCurrenciesChanged:
print("Virtual-currency balances changed — re-read balances")
case .remoteConfigChanged:
print("Remote config changed — re-read values")
}
}
}import dev.rovenue.sdk.Rovenue
import dev.rovenue.sdk.ChangeEvent
// Rovenue.shared.changes is a SharedFlow<ChangeEvent>
// Collect from a scope you own — see the warning below
viewModelScope.launch {
Rovenue.shared.changes.collect { event ->
when (event) {
ChangeEvent.ENTITLEMENTS_CHANGED -> println("Entitlements updated")
ChangeEvent.IDENTITY_CHANGED -> println("Identity changed")
ChangeEvent.VIRTUAL_CURRENCIES_CHANGED -> println("Virtual-currency balances changed")
ChangeEvent.REMOTE_CONFIG_CHANGED -> println("Remote config changed")
}
}
}Unsubscribe when done
Always clean up your subscription to prevent memory leaks or stale callbacks.
// Call the function returned by addChangeListener
unsub();
// In a React effect:
useEffect(() => {
const unsub = Rovenue.addChangeListener((event) => {
// handle event
});
return () => unsub(); // cleanup on unmount
}, []);// Cancel the Task you created in Step 1
task.cancel()
// In a SwiftUI view model, store the task and cancel on deinit:
deinit {
task.cancel()
}// If you collected with launchIn, cancel the resulting Job:
val job = Rovenue.shared.changes
.onEach { event -> /* handle */ }
.launchIn(viewModelScope)
// Cancel explicitly if needed (viewModelScope cancels automatically on ViewModel cleared):
job.cancel()Kotlin: collect changes from a coroutine scope you control (e.g. viewModelScope) — not from a scope the SDK owns. Calling shutdown() cancels the SDK's internal scope, which also cancels any collector running inside it. See App lifecycle for shutdown sequencing.
Re-read the updated cache after an event
A ChangeEvent is a signal to re-read — the event itself does not carry the new value. After receiving it, call the corresponding cache read to get the updated data.
import { Rovenue } from '@rovenue/react-native-sdk';
const unsub = Rovenue.addChangeListener(async (event) => {
switch (event) {
case 'ENTITLEMENTS_CHANGED': {
const all = await Rovenue.entitlementsAll();
console.log('Active entitlements:', all.filter(e => e.isActive));
break;
}
case 'IDENTITY_CHANGED': {
const user = await Rovenue.currentUser();
console.log('Current user:', user.rovenueId, user.appUserId);
break;
}
case 'VIRTUAL_CURRENCIES_CHANGED': {
const balances = Rovenue.virtualCurrencies();
console.log('New balances:', balances);
break;
}
case 'REMOTE_CONFIG_CHANGED': {
const config = await Rovenue.getRemoteConfig();
console.log('Remote config:', config);
break;
}
}
});let task = Task {
for await event in Rovenue.shared.changes {
switch event {
case .entitlementsChanged:
let all = await Rovenue.shared.entitlementsAll()
print("Active entitlements:", all.filter { $0.isActive })
case .identityChanged:
let user = await Rovenue.shared.currentUser()
print("Current user:", user.rovenueId, user.appUserId ?? "anonymous")
case .virtualCurrenciesChanged:
let balances = await Rovenue.shared.virtualCurrencyBalances()
print("New balances:", balances)
case .remoteConfigChanged:
let config = await Rovenue.shared.remoteConfigAllJSON()
print("Remote config:", config)
}
}
}viewModelScope.launch {
Rovenue.shared.changes.collect { event ->
when (event) {
ChangeEvent.ENTITLEMENTS_CHANGED -> {
val all = Rovenue.shared.entitlementsAll()
println("Active: ${all.filter { it.isActive }}")
}
ChangeEvent.IDENTITY_CHANGED -> {
val user = Rovenue.shared.currentUser()
println("Current user: ${user.rovenueId} / ${user.appUserId}")
}
ChangeEvent.VIRTUAL_CURRENCIES_CHANGED -> {
val balances = Rovenue.shared.virtualCurrencyBalances()
println("New balances: $balances")
}
ChangeEvent.REMOTE_CONFIG_CHANGED -> {
val config = Rovenue.shared.remoteConfigAllJson()
println("Remote config: $config")
}
}
}
}Project webhook (v1)
The project webhook URL receives one signed JSON POST per store notification, plus the deliveries Rovenue originates itself. Four producers write v1 deliveries, each in the same transaction as the change it announces: every store notification (one per inbound notification), every Rovenue-originated state change, every merge that moved a customer's records onto another subscriber (SUBSCRIBER_MERGED), and every purchase a restore transferred to another customer (SUBSCRIBER_PURCHASE_TRANSFERRED). Receipts and CSV imports write no purchase delivery of their own — every receipt-path purchase fact is also announced by the store's own notification for the same transaction. Each body names both the store's own event and the state the purchase is in after Rovenue processed it:
{
"eventType": "DID_CHANGE_RENEWAL_STATUS",
"event": "subscription.uncancelled",
"events": ["subscription.uncancelled"],
"subscriberId": "sub_123",
"appUserId": "user_42",
"rovenueId": "rov_9f2c…",
"survivorSubscriberId": "sub_123",
"aliases": ["user_42"],
"purchaseId": "pur_456",
"storeOriginalTransactionId": "2000000123456789",
"store": "APPLE",
"environment": "PRODUCTION",
"productId": "prod_789",
"productIdentifier": "pro_monthly",
"status": "ACTIVE",
"expiresDate": "2030-01-01T00:00:00.000Z",
"autoRenewStatus": true,
"webhookEventId": "whe_abc",
"timestamp": "2026-10-02T12:00:00.000Z"
}eventTypeis the store's own event, unchanged — or, for a Rovenue-originated delivery, one ofEXPIRATION,RECONCILIATION,SCHEDULED_CANCEL,SCHEDULED_REVOKE,MANUAL_GRANT,MANUAL_REVOKE,OPERATOR_REFUND; orSUBSCRIBER_MERGED/SUBSCRIBER_PURCHASE_TRANSFERRED(see Merges and transfers).eventsnames every key the delivery carries, in order: lifecycle keys first, thensubscription.product_changed/subscription.offer_redeemed/subscription.price_increase_pending/subscription.price_increase_accepted, then the revenue key(s) (revenue.<TYPE>). A recovery delivery readsevent: "subscription.recovered"withevents: ["subscription.recovered", "revenue.RENEWAL"].eventisevents[0], ornullwhen the delivery names no key. That happens only when the source changed nothing a key describes: AppleRENEWAL_EXTENDED,RENEWAL_EXTENSION,PRICE_INCREASE,REFUND_DECLINED,CONSUMPTION_REQUEST,TEST; GoogleSUBSCRIPTION_PAUSE_SCHEDULE_CHANGED,SUBSCRIPTION_PRICE_CHANGE_CONFIRMED,SUBSCRIPTION_PRICE_CHANGE_UPDATED,SUBSCRIPTION_PRICE_STEP_UP_CONSENT_UPDATED; or a stale or withheld delivery. ApplePRICE_INCREASEand Google's two price-change notifications namesubscription.price_increase_pendingorsubscription.price_increase_acceptedwhen they move the recorded price change, andnullwhen they repeat it (Price changes). A cancel (auto-renew turned off) is not in that list — it deliversevent: "subscription.cancel_requested"withautoRenewStatus: false, and the matching un-cancel deliverssubscription.uncancelledwithautoRenewStatus: true.store,productId,productIdentifier,status,expiresDateandautoRenewStatusare the purchase's state at delivery time. They arenullwhen the notification names no purchase.environmentis"PRODUCTION"or"SANDBOX": the environment of the purchase (or, when no purchase row exists yet, of the signed store transaction). Sandbox deliveries are sent too, labelled, so you can test with TestFlight or license-tester purchases. It isnullwhen neither names one: never book anulldelivery as production revenue.- Deliveries are deduplicated per inbound store notification (
webhookEventId), so a store redelivery is sent once while a cancel and the later un-cancel are two deliveries. - Deliveries Rovenue originates without a store notification carry
"webhookEventId": null: the scheduled expiry (eventType: "EXPIRATION",event: "subscription.expired"), a scheduled cancellation (event: "subscription.cancel_requested"), a comp grant (eventType: "MANUAL_GRANT",event: "revenue.INITIAL"), an immediate comp revoke (eventType: "MANUAL_REVOKE",event: "subscription.expired",eventsending inrevenue.CANCELLATION) and an operator refund (eventType: "OPERATOR_REFUND"). They are sent once per purchase and event, not per store notification — do not usewebhookEventIdas their idempotency key.
Mapping a delivery to your user
subscriberId is Rovenue's internal subscriber id. Map a delivery with the keys every body carries, resolved when the delivery is sent (so a retry after a merge names the customer it belongs to now):
appUserId— the label your app identified the customer with, on the live subscriber the event's subscriber stands for now;nullwhile the customer never identified, or after an erasure.rovenueId— the install id of the subscriber the event was recorded on.survivorSubscriberId— the live subscriber that one stands for now: itself, or the subscriber it was merged into.aliases— the survivor's labels: its live one first, then the ones merges carried onto it.storeOriginalTransactionId— on a delivery about a purchase: Apple'soriginalTransactionId, the Stripe id, or the first 24 characters of a Google Play purchase token (the full token never leaves Rovenue).
Merges and transfers
A purchase can reach Rovenue as a store notification before your app sends its receipt. It then lands on an anonymous buyer (appUserId: null) and its delivery names that buyer. When the app's receipt or an identify later merges the buyer into the identified customer, a SUBSCRIBER_MERGED delivery follows:
{
"eventType": "SUBSCRIBER_MERGED",
"event": "subscriber.merged",
"events": ["subscriber.merged"],
"subscriberId": "sub_123",
"fromSubscriberId": "sub_anon",
"toSubscriberId": "sub_123",
"appUserId": "user_42",
"rovenueId": "rov_9f2c…",
"survivorSubscriberId": "sub_123",
"aliases": ["user_42"],
"reason": "RECEIPT_MERGE",
"purchaseIds": ["pur_456"],
"moved": { "purchases": 1, "access": 1, "creditsPerCurrency": {} },
"purchaseId": null,
"webhookEventId": null,
"timestamp": "2026-11-22T12:00:00.000Z"
}- It is sent only when the merge moved something — purchases, access or a virtual-currency balance. An anonymous profile that logs in with nothing on it sends nothing.
reasonis why the merge ran:RECEIPT_MERGE,IDENTIFY,FUNNEL_CLAIM,S2S_TRANSFER,COPILOT.- The purchase deliveries already sent are not replayed under the customer. Re-point what you booked for
fromSubscriberId(or for thepurchaseIds) toappUserId, without granting again.
When a purchase moves from one customer to another without a merge, a SUBSCRIBER_PURCHASE_TRANSFERRED delivery carries the purchase's state like a store delivery, plus fromSubscriberId, fromAppUserId, toSubscriberId, purchaseIds (every row that moved, in one delivery), reason and behavior. reason is:
transfer_behavior— a store restore moved the purchase under the project's transfer behavior (behaviornames it);previous_owner_erased— the previous owner was erased (fromSubscriberId: null);restore— a web-funnel buyer restored the purchase through the emailed restore link (store: "STRIPE",behavior: null).
Revoke what the previous customer was granted for it; appUserId names the new owner.
Both events are always delivered: they have no category, so an endpoint's category filter cannot drop them. If you don't need them, ignore them by eventType.
Make your handler order-independent. Deliveries are not ordered: a merge can arrive before or after the purchase delivery it concerns, and retries reorder them further. A customer can be merged more than once (anonymous buyer → device → account): follow survivorSubscriberId and aliases rather than the first id you saw.
Related reads: Checking entitlements · Identifying users · Virtual Currencies.