Skip to content

Commit cbe1783

Browse files
Add internal API to debug tracked events on iOS (#1612)
Depends on RevenueCat/purchases-hybrid-common#1502 This provides some visibility on what events are tracked and when on iOS. This can help debug any issues with these events. iOS counterpart of #1562. Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 28290ae commit cbe1783

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

examples/purchaseTesterTypescript/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ const App = () => {
8686
diagnosticsEnabled: true,
8787
});
8888
}
89-
Purchases.addTrackedEventListener((event: Record<string, unknown>) => {
90-
console.log('[RCTrackedEvent]', JSON.stringify(event, null, 2));
91-
});
9289
Purchases.addDebugEventListener((event: Record<string, unknown>) => {
9390
console.log('[RCDebugEvent]', JSON.stringify(event, null, 2));
9491
});
@@ -99,6 +96,9 @@ const App = () => {
9996
diagnosticsEnabled: true
10097
});
10198
}
99+
Purchases.addTrackedEventListener((event: Record<string, unknown>) => {
100+
console.log('[RCTrackedEvent]', JSON.stringify(event, null, 2));
101+
});
102102

103103
Purchases.enableAdServicesAttributionTokenCollection();
104104
}, []);

ios/RNPurchases.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ static void logUnavailablePresentCodeRedemptionSheet() {
566566
}];
567567
}
568568

569+
RCT_EXPORT_METHOD(setTrackedEventListener) {
570+
[RCCommonFunctionality setTrackedEventListenerOnEventReceived:^(NSDictionary<NSString *, id> * _Nonnull eventDetails) {
571+
[self sendEventWithName:RNPurchasesTrackedEvent body:eventDetails];
572+
}];
573+
}
574+
569575
RCT_EXPORT_METHOD(isWebPurchaseRedemptionURL:(NSString *)urlString
570576
resolve:(RCTPromiseResolveBlock)resolve
571577
reject:(RCTPromiseRejectBlock)reject) {

src/purchases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,15 @@ export default class Purchases {
860860
/**
861861
* Sets a function to be called when a feature event is tracked by RevenueCatUI.
862862
* This is a debug API for monitoring paywall and customer center events not meant for public use.
863-
* Currently only works on Android.
863+
* Currently only works on Android and iOS.
864864
* @internal
865865
* @param {TrackedEventListener} trackedEventListener TrackedEvent listener
866866
*/
867867
public static async addTrackedEventListener(
868868
trackedEventListener: TrackedEventListener
869869
): Promise<void> {
870870
await Purchases.throwIfNotConfigured();
871-
if (Platform.OS === "android") {
871+
if (Platform.OS === "android" || Platform.OS === "ios") {
872872
if (typeof trackedEventListener !== "function") {
873873
throw new Error("addTrackedEventListener needs a function");
874874
}

0 commit comments

Comments
 (0)