From 9f71af9ddcc903c0149cd0fc0f27367b54c2001f Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Wed, 2 Oct 2024 18:21:08 +0500 Subject: [PATCH] chore: fix in-app site id (#341) --- Apps/APN/App.js | 5 +- .../android/app/google-services.json.example | 46 ------------------- Apps/APN/package.json | 4 +- Apps/APN/src/services/CustomerIOService.js | 14 ++++-- Apps/FCM/App.tsx | 3 +- Apps/FCM/src/services/CustomerIOService.ts | 29 ++++++------ src/customerio-cdp.ts | 7 +-- ...InAppMessaging.tsx => customerio-inapp.ts} | 0 8 files changed, 33 insertions(+), 75 deletions(-) delete mode 100644 Apps/APN/android/app/google-services.json.example rename src/{CustomerIOInAppMessaging.tsx => customerio-inapp.ts} (100%) diff --git a/Apps/APN/App.js b/Apps/APN/App.js index 79da9d19..e273c28b 100644 --- a/Apps/APN/App.js +++ b/Apps/APN/App.js @@ -32,8 +32,9 @@ export default function App() { prepare(); const inAppEventListener = registerInAppEventListener(); - // TODO: Add this when inapp feature is implemented - // inAppEventListener.remove(); + return () => { + inAppEventListener.remove(); + }; }, [ applyCustomerIoConfig, handleCustomerIoConfigChanged, diff --git a/Apps/APN/android/app/google-services.json.example b/Apps/APN/android/app/google-services.json.example deleted file mode 100644 index 24a3fa28..00000000 --- a/Apps/APN/android/app/google-services.json.example +++ /dev/null @@ -1,46 +0,0 @@ -{ - "project_info": { - "project_number": "XXXXXX", - "project_id": "XXXXX", - "storage_bucket": "XXXXX.appspot.com" - }, - "client": [ - { - "client_info": { - "mobilesdk_app_id": "1:9876789098767:android:7878789098989898987678", - "android_client_info": { - "package_name": "io.customer.ami" - } - }, - "oauth_client": [ - { - "client_id": "9876789098767-74747474747474747474747474747474.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "747474747474747474747474747474744323455" - } - ], - "services": { - "appinvite_service": { - "other_platform_oauth_client": [ - { - "client_id": "9876789098767-74747474747474747474747474747474.apps.googleusercontent.com", - "client_type": 3 - }, - { - "client_id": "9876789098767-74747474747474747474747474747474.apps.googleusercontent.com", - "client_type": 2, - "ios_info": { - "bundle_id": "io.customer.ami" - } - } - ] - } - } - } - ], - "configuration_version": "1" -} \ No newline at end of file diff --git a/Apps/APN/package.json b/Apps/APN/package.json index ce729f1d..4cc8355b 100644 --- a/Apps/APN/package.json +++ b/Apps/APN/package.json @@ -11,8 +11,8 @@ "clean-install-ios": "./scripts/clean-run-ios.sh", "dev:update": "../../scripts/dev:update.sh", "postinstall": "pod update --project-directory=ios", - "preinstall": "npm run dev:update --legacy-peer-deps", - "ci:install": "npm run preinstall && npm ci --legacy-peer-deps && npm run bundle:ios" + "preinstall": "npm run dev:update", + "ci:install": "npm run preinstall && npm ci" }, "dependencies": { "@react-native-async-storage/async-storage": "^1.19.1", diff --git a/Apps/APN/src/services/CustomerIOService.js b/Apps/APN/src/services/CustomerIOService.js index ac0f6565..55f5fcd3 100644 --- a/Apps/APN/src/services/CustomerIOService.js +++ b/Apps/APN/src/services/CustomerIOService.js @@ -1,4 +1,8 @@ -import { CustomerIO, CioLogLevel } from 'customerio-reactnative'; +import { + CustomerIO, + CioLogLevel, + InAppMessageEventType, +} from 'customerio-reactnative'; export const initializeCustomerIoSDK = (sdkConfig) => { const config = { @@ -7,7 +11,7 @@ export const initializeCustomerIoSDK = (sdkConfig) => { trackApplicationLifecycleEvents: sdkConfig.trackAppLifecycleEvents, autoTrackDeviceAttributes: sdkConfig.autoTrackDeviceAttributes, inApp: { - siteId: 'site_id', + siteId: sdkConfig.siteId, }, }; @@ -65,7 +69,7 @@ export const requestPushNotificationsPermission = (options) => { // TODO: Implement this method when inapp feature is added export const registerInAppEventListener = () => { - /*const logInAppEvent = (name, params) => { + const logInAppEvent = (name, params) => { console.log(`in-app message: ${name}, params: `, params); }; @@ -88,7 +92,7 @@ export const registerInAppEventListener = () => { CustomerIO.track('in-app message action', data); }; - const inAppMessaging = CustomerIO.inAppMessaging(); + const inAppMessaging = CustomerIO.inAppMessaging; return inAppMessaging.registerEventsListener((event) => { switch (event.eventType) { case InAppMessageEventType.messageShown: @@ -114,5 +118,5 @@ export const registerInAppEventListener = () => { default: onInAppEventReceived('unsupported event', event); } - });*/ + }); }; diff --git a/Apps/FCM/App.tsx b/Apps/FCM/App.tsx index 3efc7f9e..8834c0c2 100644 --- a/Apps/FCM/App.tsx +++ b/Apps/FCM/App.tsx @@ -87,8 +87,7 @@ export default function App() { // Remove listeners once unmounted return () => { - // TODO: Add this when inapp feature is implemented - // inAppEventListener.remove(); + inAppEventListener.remove(); }; }, [ applyCustomerIoConfig, diff --git a/Apps/FCM/src/services/CustomerIOService.ts b/Apps/FCM/src/services/CustomerIOService.ts index f0e70fc6..0ae8641c 100644 --- a/Apps/FCM/src/services/CustomerIOService.ts +++ b/Apps/FCM/src/services/CustomerIOService.ts @@ -1,7 +1,9 @@ import { CioLogLevel, CustomerIO, - CioPushPermissionOptions + CioPushPermissionOptions, + InAppMessageEvent, + InAppMessageEventType, } from 'customerio-reactnative'; import User from '../data/models/user'; import CustomerIoSDKConfig from '../data/sdk/CustomerIoSDKConfig'; @@ -13,22 +15,23 @@ export const initializeCustomerIoSDK = (sdkConfig: CustomerIoSDKConfig) => { trackApplicationLifecycleEvents: sdkConfig.trackAppLifecycleEvents, autoTrackDeviceAttributes: sdkConfig.trackDeviceAttributes, inApp: { - siteId: 'site_id', + siteId: sdkConfig.siteId, }, logLevel: CioLogLevel.None, // Add logLevel property }; - if (sdkConfig.debugMode) { - config.logLevel = CioLogLevel.Debug; -} -CustomerIO.initialize(config) + if (sdkConfig.debugMode) { + config.logLevel = CioLogLevel.Debug; + } + CustomerIO.initialize(config) }; export const onUserLoggedIn = (user: User) => { - CustomerIO.identify({ id: user.email, + CustomerIO.identify({ + id: user.email, traits: { - first_name: user.name, - email: user.email, - } + first_name: user.name, + email: user.email, + } }); }; @@ -71,7 +74,7 @@ export const requestPushNotificationsPermission = ( export const registerInAppEventListener = () => { - /*const logInAppEvent = (name: string, params: InAppMessageEvent) => { + const logInAppEvent = (name: string, params: InAppMessageEvent) => { console.log(`in-app message: ${name}, params: `, params); }; @@ -96,7 +99,7 @@ export const registerInAppEventListener = () => { CustomerIO.track('in-app message action', data); }; - const inAppMessaging = CustomerIO.inAppMessaging(); + const inAppMessaging = CustomerIO.inAppMessaging; return inAppMessaging.registerEventsListener((event: InAppMessageEvent) => { switch (event.eventType) { case InAppMessageEventType.messageShown: @@ -122,5 +125,5 @@ export const registerInAppEventListener = () => { default: onInAppEventReceived('unsupported event', event); } - }); */ + }); }; diff --git a/src/customerio-cdp.ts b/src/customerio-cdp.ts index e20b91f9..fb58aca3 100644 --- a/src/customerio-cdp.ts +++ b/src/customerio-cdp.ts @@ -1,9 +1,7 @@ import { NativeModules, Platform } from 'react-native'; import { CioLogLevel, type CioConfig } from './cio-config'; import { type IdentifyParams } from './cio-params'; -// TODO: Import the CustomerIOInAppMessaging class from their respective files -// when they are implemented. -// import { CustomerIOInAppMessaging } from './customerio-inapp'; +import { CustomerIOInAppMessaging } from './customerio-inapp'; import { CustomerIOPushMessaging } from './customerio-push'; import { NativeLoggerListener } from './native-logger-listener'; @@ -97,8 +95,7 @@ export class CustomerIO { static readonly isInitialized = () => CustomerIO.initialized; - // TODO: Update when implemented. - // static readonly inAppMessaging = new CustomerIOInAppMessaging(); + static readonly inAppMessaging = new CustomerIOInAppMessaging(); static readonly pushMessaging = new CustomerIOPushMessaging(); private static readonly assrtInitialized = () => { diff --git a/src/CustomerIOInAppMessaging.tsx b/src/customerio-inapp.ts similarity index 100% rename from src/CustomerIOInAppMessaging.tsx rename to src/customerio-inapp.ts