From 8858149307dcab1bc5a5ba7ae2ac8c80efbf1e4a Mon Sep 17 00:00:00 2001 From: Dhruv Porwal Date: Sat, 28 Mar 2026 19:47:03 +0530 Subject: [PATCH 1/3] feat: stream smallplug analytics events via EventChannel --- .../app/screens/SmtScreen.tsx | 13 +++++-- src/SCGatewayEventEmitter.js | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/smart_investing_react_native/app/screens/SmtScreen.tsx b/smart_investing_react_native/app/screens/SmtScreen.tsx index dee1fe83..b3d0cde1 100644 --- a/smart_investing_react_native/app/screens/SmtScreen.tsx +++ b/smart_investing_react_native/app/screens/SmtScreen.tsx @@ -1,6 +1,7 @@ import React from 'react'; import {Button, TextInput, View} from 'react-native'; import {launchSmallPlug} from '../apis/Functions'; +import {SCGatewayEventManager} from 'react-native-smallcase-gateway'; const SmtScreen = () => { const [targetEndpoint, onChangeTargetEndpoint] = React.useState< @@ -70,6 +71,12 @@ const SmtScreen = () => { backIconOpacity: bo, }; + const smallplugSub = SCGatewayEventManager.subscribeToSmallplugEvents( + event => { + console.log('[SmallPlug Event]:', event); + }, + ); + try { const result = await launchSmallPlug( targetEndpoint, @@ -79,16 +86,14 @@ const SmtScreen = () => { console.log('✅ Smallplug Success:', result); if (result?.data?.userInfo) { console.log(' User Info:', result.data.userInfo); - // You can use the userInfo object here, for example, show an alert - // alert(`Success! User phone: ${result.data.userInfo.phoneNumber}`); } } catch (error: any) { console.error(' Smallplug Error:', error); if (error?.data?.userInfo) { console.log(' User Info from error:', error.data.userInfo); - // You can use the userInfo object here - // alert(`Failure! User phone: ${error.data.userInfo.phoneNumber}`); } + } finally { + smallplugSub?.remove(); } }} title={'SmallPlug'} diff --git a/src/SCGatewayEventEmitter.js b/src/SCGatewayEventEmitter.js index 7bcfcf74..bfdaefcd 100644 --- a/src/SCGatewayEventEmitter.js +++ b/src/SCGatewayEventEmitter.js @@ -18,6 +18,7 @@ export const SCGatewayEventTypes = { SUPER_PROPERTIES_UPDATED: 'scgateway_super_properties_updated', USER_RESET: 'scgateway_user_reset', USER_IDENTIFY: 'scgateway_user_identify', + SMALLPLUG_ANALYTICS_EVENT: 'smallplug_analytics_event', }; const SCGatewayNotificationEvent = 'scg_notification'; @@ -104,6 +105,43 @@ class SCGatewayEvents { return subscription; } + /** + * Subscribe to SmallPlug / DM analytics events streamed during a launchSmallplug session. + * Events have shape: { eventName: string, data: object, timestamp: number } + * @param {(event: {eventName: string, data: any, timestamp: number}) => void} callback + * @returns {GatewayEventSubscription} + */ + subscribeToSmallplugEvents(callback) { + if (!this.isInitialized) { + console.warn('[SCGatewayEvents] Event emitter not initialized'); + return null; + } + + if (typeof callback !== 'function') { + console.warn('[SCGatewayEvents] Invalid callback provided for SmallPlug subscription'); + return null; + } + + const subscription = this.eventEmitter.addListener( + SCGatewayNotificationEvent, + (jsonString) => { + if (!jsonString) return; + let parsed; + try { + parsed = JSON.parse(jsonString); + } catch (e) { + return; + } + if (parsed.type !== 'smallplug_analytics_event') return; + const { eventName, data } = parsed.data ?? {}; + callback({ eventName, data, timestamp: parsed.timestamp ?? Date.now() }); + } + ); + + this.subscriptions.push(subscription); + return subscription; + } + /** * Unsubscribe from Gateway Events * @param {GatewayEventSubscription} subscription - Subscription returned from subscribeToGatewayEvents From 8c61207516271523e2108867eb8ceea23600f9e5 Mon Sep 17 00:00:00 2001 From: Dhruv Porwal Date: Sat, 28 Mar 2026 19:57:13 +0530 Subject: [PATCH 2/3] bump up sdk versions --- android/build.gradle | 2 +- react-native-smallcase-gateway.podspec | 2 +- types/index.d.ts | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 8c6c2fdd..a9f4434c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -149,7 +149,7 @@ def kotlin_version = getExtOrDefault('kotlinVersion') dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' // From node_modules - implementation 'com.smallcase.gateway:sdk:6.0.5' + implementation 'com.smallcase.gateway:sdk-dhruv-propagate-dm-events-17a02a6:6.0.5-3186-release' implementation 'com.smallcase.loans:sdk:5.1.1' implementation "androidx.core:core-ktx:1.3.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" diff --git a/react-native-smallcase-gateway.podspec b/react-native-smallcase-gateway.podspec index 72143205..23eb5783 100644 --- a/react-native-smallcase-gateway.podspec +++ b/react-native-smallcase-gateway.podspec @@ -34,6 +34,6 @@ Pod::Spec.new do |s| s.dependency "ReactCommon/turbomodule/core" end - s.dependency 'SCGateway', '7.1.5' + s.dependency 'SCGateway-dhruv-propagate-dm-events-baa3bc0', '7.1.0-17-debug' s.dependency 'SCLoans', '7.1.1' end diff --git a/types/index.d.ts b/types/index.d.ts index 66417fb5..285687c9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -12,6 +12,12 @@ export interface LoansEvent { timestamp: number; } +export interface SmallplugAnalyticsEvent { + eventName: string; + data: Record; + timestamp: number; +} + export interface GatewayEventSubscription { remove(): void; } @@ -22,6 +28,7 @@ export interface LoansEventSubscription { interface SCGatewayEventManagerInterface { subscribeToGatewayEvents(callback: ((event: GatewayEvent) => void)): GatewayEventSubscription | null; + subscribeToSmallplugEvents(callback: ((event: SmallplugAnalyticsEvent) => void)): GatewayEventSubscription | null; unsubscribeFromGatewayEvents(subscription: GatewayEventSubscription): void; } @@ -86,6 +93,7 @@ declare const _default: { SCLoansEventManager: SCLoansEventManagerInterface; subscribeToGatewayEvents: (callback: (event: GatewayEvent) => void) => GatewayEventSubscription | null; unsubscribeFromGatewayEvents: (subscription: GatewayEventSubscription) => void; + subscribeToSmallplugEvents: (callback: (event: SmallplugAnalyticsEvent) => void) => GatewayEventSubscription | null; subscribeToLoansEvent: (callback: (event: LoansEvent) => void) => LoansEventSubscription | null; unsubscribeFromLoansEvent: (subscription: LoansEventSubscription) => void; }; From c1d5a7c1a873b9da04e9bffe381e8d72fe3026b9 Mon Sep 17 00:00:00 2001 From: Dhruv Porwal Date: Sat, 28 Mar 2026 21:52:29 +0530 Subject: [PATCH 3/3] feat: stream smallplug analytics events via EventChannel --- react-native-smallcase-gateway.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native-smallcase-gateway.podspec b/react-native-smallcase-gateway.podspec index 23eb5783..f321846b 100644 --- a/react-native-smallcase-gateway.podspec +++ b/react-native-smallcase-gateway.podspec @@ -34,6 +34,6 @@ Pod::Spec.new do |s| s.dependency "ReactCommon/turbomodule/core" end - s.dependency 'SCGateway-dhruv-propagate-dm-events-baa3bc0', '7.1.0-17-debug' + s.dependency 'SCGateway-dhruv-propagate-dm-events-eaf8710', '7.1.0-18-debug' s.dependency 'SCLoans', '7.1.1' end