Skip to content

Instantly share code, notes, and snippets.

@farzd
Last active September 13, 2025 09:01
Show Gist options
  • Select an option

  • Save farzd/7dd1978a4608cf5c288edd3304152182 to your computer and use it in GitHub Desktop.

Select an option

Save farzd/7dd1978a4608cf5c288edd3304152182 to your computer and use it in GitHub Desktop.
Revenue Cat One Signal
// Problem = We can see OneSignal ID associated with a Revenue Cat User in the Revenue Cat dashboard,
// the One Signal ID is available in their dashboard too with the correct external_id BUT Revenue Cat event is 404 ?
/*
* Packages
* package.json
*/
{
"onesignal-expo-plugin": "^2.0.3",
"react-native-onesignal": "^5.2.13",
"react-native-purchases": "^8.11.10",
"react-native-purchases-ui": "^8.11.10"
}
/*
* App init
* Initialise Purchases and One Signal
*/
usePurchasesInitialize({
userId,
});
usePurchasesMonitor();
// Setup notification permissions monitoring
useNotificationPermissions(userId);
useEffect(() => {
if (userId) {
// Enable verbose logging for debugging (remove in production)
if (__DEV__) {
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
}
OneSignal.initialize(oneSignalAppId);
OneSignal.login(userId);
}
}, [userId]);
/*
* OneSignal Hook
* Event listeners to sync with RC when we have correct One Signal ID
* After OneSignal.login(userId) / when we get external ID (since One Signal ID can change due to these updates)
*/
export const syncOnesignalWithRevenueCat = async (onesignalId) => {
try {
const isConfigured = await Purchases.isConfigured();
console.log("Purchases Configured", isConfigured, onesignalId);
if (isConfigured) {
await Purchases.setOnesignalID(onesignalId);
console.log("OneSignal ID synced with RevenueCat:", onesignalId);
}
} catch (error) {
console.warn("Failed to sync OneSignal ID with RevenueCat:", error);
}
};
export const useNotificationPermissions = (userId) => {
useEffect(() => {
if (!userId) return;
// Handle OneSignal push subscription changes to sync with RevenueCat
const onUserStatusChange = async (event) => {
const onesignalID = event.current?.onesignalId;
if (onesignalID) {
await syncOnesignalWithRevenueCat(onesignalID);
const { error } = await supabase
.from("profiles")
.update({ push_token: onesignalID })
.eq("id", userId);
}
};
OneSignal.User.addEventListener("change", onUserStatusChange);
return () => {
OneSignal.User.removeEventListener("change", onUserStatusChange);
};
}, [userId]);
};
@farzd
Copy link
Author

farzd commented Sep 13, 2025

One Signal chats =
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment