From 3341db8977ec0db86eaf10f4a14e217efb78bc3d Mon Sep 17 00:00:00 2001 From: "soumen.rautray" <96281209+SoumenRautray@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:45:09 +0530 Subject: [PATCH] chore: Implement console warning if LogEvent is called before RegisterPreference (RMCCX-7109) --- CHANGELOG.md | 1 + Sources/RInAppMessaging/RInAppMessaging.swift | 5 +++++ Sources/RInAppMessaging/Utilities/AnalyticsTracker.swift | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b5425f..3ed04aa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Redirect user to App Notification Permission Settings if permission was denied previously in Push Primer [RMCCX-6710] - Send RMC impression event to RAT [RMCCX-6939] - Send RMC push primer event to RAT [RMCCX-6938] + - Implement console warning if LogEvent is called before calling RegisterPreference [RMCCX-7109] ### 8.3.0 (2024-05-13) - Improvements: diff --git a/Sources/RInAppMessaging/RInAppMessaging.swift b/Sources/RInAppMessaging/RInAppMessaging.swift index 1bb625d1..60a7bf3f 100644 --- a/Sources/RInAppMessaging/RInAppMessaging.swift +++ b/Sources/RInAppMessaging/RInAppMessaging.swift @@ -23,6 +23,7 @@ import RSDKUtils internal static var isInitialized: Bool { interactor.iamModule != nil } + internal static var isUserRegistered: Bool = false internal static let interactor = InAppMessagingInteractor() /// Returns `true` when RMC module is integrated in the host app @@ -124,6 +125,9 @@ import RSDKUtils /// Log the event name passed in and also pass the event name to the view controller to display a matching campaign. /// - Parameter event: The Event object to log. @objc public static func logEvent(_ event: Event) { + if !isUserRegistered { + Logger.debug("⚠️ Warning: RegisterPreference should be called before logging any Events.") + } inAppQueue.async { interactor.logEvent(event) } @@ -136,6 +140,7 @@ import RSDKUtils /// - Note: This method creates a strong reference to provided object. /// - Parameter provider: object that will always contain up-to-date user information. @objc public static func registerPreference(_ provider: UserInfoProvider) { + isUserRegistered = true inAppQueue.async { interactor.userPerference = provider } diff --git a/Sources/RInAppMessaging/Utilities/AnalyticsTracker.swift b/Sources/RInAppMessaging/Utilities/AnalyticsTracker.swift index a7455f06..dfb343db 100644 --- a/Sources/RInAppMessaging/Utilities/AnalyticsTracker.swift +++ b/Sources/RInAppMessaging/Utilities/AnalyticsTracker.swift @@ -14,7 +14,9 @@ internal struct AnalyticsTracker { if let customAccNumber = BundleInfo.rmcRATAccountId, RInAppMessaging.isRMCEnvironment { let rmcEventName = name.rawValue == Constants.RAnalytics.impressionsEventName.rawValue ? Constants.RAnalytics.rmcImpressionsEventName : Constants.RAnalytics.rmcPushPrimerEventName AnalyticsBroadcaster.sendEventName(rmcEventName.rawValue, dataObject: eventData, customAccountNumber: customAccNumber) + AnalyticsBroadcaster.sendEventName(rmcEventName.rawValue, dataObject: eventData) + } else { + AnalyticsBroadcaster.sendEventName(name.rawValue, dataObject: eventData) } - AnalyticsBroadcaster.sendEventName(name.rawValue, dataObject: eventData) } }