diff --git a/Sources/Clickstream/AWSClickstreamPlugin+Configure.swift b/Sources/Clickstream/AWSClickstreamPlugin+Configure.swift index ba68346..f87b83d 100644 --- a/Sources/Clickstream/AWSClickstreamPlugin+Configure.swift +++ b/Sources/Clickstream/AWSClickstreamPlugin+Configure.swift @@ -117,6 +117,13 @@ extension AWSClickstreamPlugin { } else if amplifyConfigure.isCompressEvents != nil { defaultConfiguration.isCompressEvents = amplifyConfigure.isCompressEvents } + + mergeDefaultConfiguration(defaultConfiguration) + configuration = defaultConfiguration + } + + /// Internal method to merge the default configurations + func mergeDefaultConfiguration(_ defaultConfiguration: ClickstreamConfiguration) { if let isTrackScreenViewEvents = configuration.isTrackScreenViewEvents { defaultConfiguration.isTrackScreenViewEvents = isTrackScreenViewEvents } @@ -135,7 +142,6 @@ extension AWSClickstreamPlugin { if configuration.globalAttributes != nil { defaultConfiguration.globalAttributes = configuration.globalAttributes } - configuration = defaultConfiguration } /// Internal method to add global attributes diff --git a/Sources/Clickstream/ClickstreamAnalytics.swift b/Sources/Clickstream/ClickstreamAnalytics.swift index b16bf60..b39a4c7 100644 --- a/Sources/Clickstream/ClickstreamAnalytics.swift +++ b/Sources/Clickstream/ClickstreamAnalytics.swift @@ -94,7 +94,9 @@ public enum ClickstreamAnalytics { var amplifyConfiguraion: AmplifyConfiguration! do { guard let path = bundle.path(forResource: "amplifyconfiguration", ofType: "json") else { - throw ConfigurationError.invalidAmplifyConfigurationFile("Could not load default `amplifyconfiguration.json` file", "please check if you added the correct configuration file") + throw ConfigurationError.invalidAmplifyConfigurationFile( + "Could not load default `amplifyconfiguration.json` file", + "please check if you added the correct configuration file") } let url = URL(fileURLWithPath: path) amplifyConfiguraion = try AmplifyConfiguration(configurationFile: url) @@ -103,8 +105,8 @@ public enum ClickstreamAnalytics { let plugins: [String: JSONValue] = [ "awsClickstreamPlugin": [ "appId": JSONValue.string(""), - "endpoint": JSONValue.string(""), - ], + "endpoint": JSONValue.string("") + ] ] let analyticsConfiguration = AnalyticsCategoryConfiguration(plugins: plugins) amplifyConfiguraion = AmplifyConfiguration(analytics: analyticsConfiguration) diff --git a/Tests/ClickstreamTests/Clickstream/AutoRecordEventClientTest.swift b/Tests/ClickstreamTests/Clickstream/AutoRecordEventClientTest.swift index b71e43a..4d9f178 100644 --- a/Tests/ClickstreamTests/Clickstream/AutoRecordEventClientTest.swift +++ b/Tests/ClickstreamTests/Clickstream/AutoRecordEventClientTest.swift @@ -22,7 +22,7 @@ class AutoRecordEventClientTest: XCTestCase { UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!) let mockNetworkMonitor = MockNetworkMonitor() activityTracker = MockActivityTracker() - + let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration() .withAppId(testAppId) .withEndpoint(testEndpoint) diff --git a/Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift b/Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift index 10a2943..69e6d7e 100644 --- a/Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift +++ b/Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift @@ -41,7 +41,7 @@ class EventRecorderTest: XCTestCase { } try! server.start() let appId = testAppId + String(describing: Date().millisecondsSince1970) - + let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration() .withAppId(appId) .withEndpoint(testSuccessEndpoint) diff --git a/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift b/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift index dad5bfc..1cb1798 100644 --- a/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift +++ b/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift @@ -258,15 +258,15 @@ class SessionClientTests: XCTestCase { let state1 = ApplicationState.Resolver.resolve(currentState: ApplicationState.terminated, event: ActivityEvent.applicationWillMoveToForeground) XCTAssertEqual(ApplicationState.terminated, state1) - + let state2 = ApplicationState.Resolver.resolve(currentState: ApplicationState.runningInBackground, event: ActivityEvent.applicationWillTerminate) XCTAssertEqual(ApplicationState.terminated, state2) - + let state3 = ApplicationState.Resolver.resolve(currentState: ApplicationState.runningInBackground, event: ActivityEvent.applicationDidMoveToBackground) XCTAssertEqual(ApplicationState.runningInBackground, state3) - + let state4 = ApplicationState.Resolver.resolve(currentState: ApplicationState.runningInForeground, event: ActivityEvent.applicationWillMoveToForeground) XCTAssertEqual(ApplicationState.runningInForeground, state4) diff --git a/Tests/ClickstreamTests/ClickstreamPluginTestBase.swift b/Tests/ClickstreamTests/ClickstreamPluginTestBase.swift index 9324999..6b018e0 100644 --- a/Tests/ClickstreamTests/ClickstreamPluginTestBase.swift +++ b/Tests/ClickstreamTests/ClickstreamPluginTestBase.swift @@ -19,7 +19,7 @@ class ClickstreamPluginTestBase: XCTestCase { override func setUp() async throws { mockNetworkMonitor = MockNetworkMonitor() analyticsPlugin = AWSClickstreamPlugin() - + let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration() .withAppId(testAppId) .withEndpoint(testEndpoint) diff --git a/Tests/ClickstreamTests/SDKInitialTest.swift b/Tests/ClickstreamTests/SDKInitialTest.swift index cf1f6f6..63af88d 100644 --- a/Tests/ClickstreamTests/SDKInitialTest.swift +++ b/Tests/ClickstreamTests/SDKInitialTest.swift @@ -37,8 +37,8 @@ class SDKInitialTest: XCTestCase { .withEndpoint("https://example.com/collect") .withLogEvents(true) .withCompressEvents(false) - .withSessionTimeoutDuration(100000) - .withSendEventInterval(15000) + .withSessionTimeoutDuration(100_000) + .withSendEventInterval(15_000) .withTrackAppExceptionEvents(true) .withTrackScreenViewEvents(false) .withTrackUserEngagementEvents(false) @@ -58,8 +58,8 @@ class SDKInitialTest: XCTestCase { .withEndpoint("https://example.com/collect1") .withLogEvents(true) .withCompressEvents(false) - .withSessionTimeoutDuration(100000) - .withSendEventInterval(15000) + .withSessionTimeoutDuration(100_000) + .withSendEventInterval(15_000) .withTrackAppExceptionEvents(true) .withTrackScreenViewEvents(false) .withTrackUserEngagementEvents(false) @@ -79,8 +79,8 @@ class SDKInitialTest: XCTestCase { let configure = ClickstreamConfiguration() .withLogEvents(true) .withCompressEvents(false) - .withSessionTimeoutDuration(100000) - .withSendEventInterval(15000) + .withSessionTimeoutDuration(100_000) + .withSendEventInterval(15_000) .withTrackScreenViewEvents(false) .withTrackUserEngagementEvents(false) .withAuthCookie("testAuthCookie") @@ -92,8 +92,8 @@ class SDKInitialTest: XCTestCase { XCTAssertEqual("http://example.com/collect", resultConfig.endpoint) XCTAssertEqual(true, resultConfig.isLogEvents) XCTAssertEqual(false, resultConfig.isCompressEvents) - XCTAssertEqual(100000, resultConfig.sessionTimeoutDuration) - XCTAssertEqual(15000, resultConfig.sendEventsInterval) + XCTAssertEqual(100_000, resultConfig.sessionTimeoutDuration) + XCTAssertEqual(15_000, resultConfig.sendEventsInterval) XCTAssertEqual(false, resultConfig.isTrackScreenViewEvents) XCTAssertEqual(false, resultConfig.isTrackUserEngagementEvents) XCTAssertEqual("testAuthCookie", resultConfig.authCookie)