Skip to content

Commit 4d05c50

Browse files
OKTA-807366: Add firebase Analytics to OktaAnalytics sdk (#102)
OKTA-807366: Add firebase Analytics and tests to OktaAnalytics Add test cases
1 parent 3bf5d06 commit 4d05c50

File tree

10 files changed

+227
-48
lines changed

10 files changed

+227
-48
lines changed

Example/Example-iOS/SceneDelegate.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Firebase
1414
import OktaLogger
1515
import OktaAnalytics
1616
import AppCenterAnalytics
17+
import FirebaseAnalytics
1718

1819
var scenarioID: ScenarioID = ""
1920

@@ -30,18 +31,31 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
3031
defaultProperties: nil
3132
)
3233
)
33-
let appCenterAnalyticsProvider = AppCenterAnalyticsProvider(name: "AppCenter", logger: logger)
34+
let appCenterAnalyticsProvider = AppCenterAnalyticsProvider(name: "AppCenter", defaultProperties: [:], logger: logger)
3435
appCenterAnalyticsProvider.start(withAppSecret: "App Secret", services: [AppCenterAnalytics.Analytics.self])
3536
return appCenterAnalyticsProvider
3637
}()
3738

39+
let firebaseAnalyticsProvider: AnalyticsProviderProtocol = {
40+
let logger = OktaLogger()
41+
logger.addDestination(
42+
OktaLoggerConsoleLogger(
43+
identifier: "com.okta.loggerDemo.console",
44+
level: OktaLoggerLogLevel.debug,
45+
defaultProperties: nil
46+
)
47+
)
48+
let firebaseAnalyticsProvider = FirebaseAnalyticsProvider(name: "Firebase Analytics", defaultProperties: [:], logger: logger)
49+
return firebaseAnalyticsProvider
50+
}()
51+
3852
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
3953
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
4054
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
4155
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
42-
FirebaseApp.configure()
4356
OktaAnalytics.initializeStorageWith(securityAppGroupIdentifier: Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String ?? "")
4457
OktaAnalytics.addProvider(appCenterAnalyticsProvider)
58+
OktaAnalytics.addProvider(firebaseAnalyticsProvider)
4559
OktaAnalytics.trackEvent("applicationDidFinishLaunchingWithOptions", withProperties: nil)
4660
OktaAnalytics.startScenario(ScenarioEvent(name: "Application", properties: [Property(key: "AppDelegate.application.didFinishLaunchingWithOptions", value: "1")])) {
4761
scenarioID = $0 ?? ""

OktaAnalytics.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "OktaAnalytics"
3-
s.version = "2.0.4"
3+
s.version = "2.1"
44
s.summary = "Implementation of Analytics logger destination"
55
s.description = "Implementation of Analytics logger destination. Requires OktaLogger/Core"
66
s.homepage = "https://github.com/okta/okta-logger-swift"
@@ -18,4 +18,5 @@ Pod::Spec.new do |s|
1818
s.dependency 'AppCenter','~>5'
1919
s.dependency 'OktaLogger/Core', '~>1'
2020
s.dependency 'OktaSQLiteStorage', '~>0.0.4'
21+
s.dependency 'Firebase/AnalyticsWithoutAdIdSupport'
2122
end

OktaLogger.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
1010
2428E650B877FD5A91A859F9 /* libPods-OktaLoggerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AB97EA576638C766A84A9DCD /* libPods-OktaLoggerTests.a */; };
1111
413B96875EB52EB482005A8F /* libPods-OktaAnalytics.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A254F4CD3A3C59AD6B7B3E8C /* libPods-OktaAnalytics.a */; };
1212
6582A2024047A1BC55BC98D3 /* LumberjackLoggerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6582AABCF4A4B6E5E05FC2E4 /* LumberjackLoggerDelegate.swift */; };
1313
6582A2C33C06B4353D1538E3 /* FileLoggerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6582ABCA2C9C2759535A1B4E /* FileLoggerDelegate.swift */; };
14+
6CCBD40A2C9CC64400E8FEEE /* FirebaseAnalyticsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CCBD4092C9CC63900E8FEEE /* FirebaseAnalyticsProvider.swift */; };
1415
7B13559F276BE69400F0516C /* OktaLoggerFirebaseLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B13559E276BE69400F0516C /* OktaLoggerFirebaseLoggerTests.swift */; };
1516
7FC038A4282467C300C16169 /* OktaLoggerLogLevel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC0389E282467C300C16169 /* OktaLoggerLogLevel.swift */; };
1617
7FC038A5282467C300C16169 /* ReadWriteLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC0389F282467C300C16169 /* ReadWriteLock.swift */; };
@@ -112,6 +113,7 @@
112113
6582ABCA2C9C2759535A1B4E /* FileLoggerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileLoggerDelegate.swift; sourceTree = "<group>"; };
113114
6C98A0E828A308FD00DA6CA9 /* OktaAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaAnalytics.swift; sourceTree = "<group>"; };
114115
6CAB2C7728DD22750020221F /* AppCenterAnalyticsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCenterAnalyticsProvider.swift; sourceTree = "<group>"; };
116+
6CCBD4092C9CC63900E8FEEE /* FirebaseAnalyticsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseAnalyticsProvider.swift; sourceTree = "<group>"; };
115117
6CD94F5828CEEB2000EE4254 /* AnalyticsProviderProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsProviderProtocol.swift; sourceTree = "<group>"; };
116118
6FE5F0352D4833C2B811B09E /* Pods-OktaAnalytics.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OktaAnalytics.release.xcconfig"; path = "Target Support Files/Pods-OktaAnalytics/Pods-OktaAnalytics.release.xcconfig"; sourceTree = "<group>"; };
117119
7B13559E276BE69400F0516C /* OktaLoggerFirebaseLoggerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OktaLoggerFirebaseLoggerTests.swift; sourceTree = "<group>"; };
@@ -467,8 +469,9 @@
467469
F3575F2D2A0AD1850008A965 /* OktaAnalytics */ = {
468470
isa = PBXGroup;
469471
children = (
470-
6CD94F5828CEEB2000EE4254 /* AnalyticsProviderProtocol.swift */,
472+
6CCBD4092C9CC63900E8FEEE /* FirebaseAnalyticsProvider.swift */,
471473
6CAB2C7728DD22750020221F /* AppCenterAnalyticsProvider.swift */,
474+
6CD94F5828CEEB2000EE4254 /* AnalyticsProviderProtocol.swift */,
472475
6C98A0E828A308FD00DA6CA9 /* OktaAnalytics.swift */,
473476
F3ACE11A29BADB03003C3403 /* Properties.swift */,
474477
F3C091352A1576780015E9FC /* AnalyticsStorage.swift */,
@@ -1102,6 +1105,7 @@
11021105
F3575F492A0AD19A0008A965 /* AnalyticsProviderProtocol.swift in Sources */,
11031106
F3575F4F2A0AD1A60008A965 /* OktaAnalytics.swift in Sources */,
11041107
F3C091392A15D2080015E9FC /* ReadWriteLock.swift in Sources */,
1108+
6CCBD40A2C9CC64400E8FEEE /* FirebaseAnalyticsProvider.swift in Sources */,
11051109
F3575F4C2A0AD1A60008A965 /* Properties.swift in Sources */,
11061110
);
11071111
runOnlyForDeploymentPostprocessing = 0;

OktaLogger.xcodeproj/xcshareddata/xcschemes/OktaLoggerDemoApp.xcscheme

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
ReferencedContainer = "container:OktaLogger.xcodeproj">
5151
</BuildableReference>
5252
</BuildableProductRunnable>
53+
<CommandLineArguments>
54+
<CommandLineArgument
55+
argument = "-FIRAnalyticsDebugEnabled"
56+
isEnabled = "YES">
57+
</CommandLineArgument>
58+
</CommandLineArguments>
5359
</LaunchAction>
5460
<ProfileAction
5561
buildConfiguration = "Release"

Podfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ target 'OktaAnalytics' do
1919
pod 'OktaSQLiteStorage', :path => '.'
2020
pod 'AppCenter', '~>5.0.0'
2121
pod 'SwiftLint', '0.51'
22+
pod 'Firebase/AnalyticsWithoutAdIdSupport'
2223
end
2324

2425
target 'OktaLoggerDemoApp' do
@@ -39,4 +40,4 @@ target 'OktaAnalyticsTests' do
3940
pod 'OktaAnalytics', :path => '.'
4041
pod 'OktaSQLiteStorage', :path => '.'
4142
pod 'AppCenter', '~>5.0.0'
42-
end
43+
end

Podfile.lock

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
PODS:
2-
- AppCenter (5.0.4):
3-
- AppCenter/Analytics (= 5.0.4)
4-
- AppCenter/Crashes (= 5.0.4)
5-
- AppCenter/Analytics (5.0.4):
2+
- AppCenter (5.0.5):
3+
- AppCenter/Analytics (= 5.0.5)
4+
- AppCenter/Crashes (= 5.0.5)
5+
- AppCenter/Analytics (5.0.5):
66
- AppCenter/Core
7-
- AppCenter/Core (5.0.4)
8-
- AppCenter/Crashes (5.0.4):
7+
- AppCenter/Core (5.0.5)
8+
- AppCenter/Crashes (5.0.5):
99
- AppCenter/Core
1010
- CocoaLumberjack/Core (3.6.2)
1111
- CocoaLumberjack/Swift (3.6.2):
1212
- CocoaLumberjack/Core
13+
- Firebase/AnalyticsWithoutAdIdSupport (9.4.0):
14+
- Firebase/CoreOnly
15+
- FirebaseAnalytics/WithoutAdIdSupport (~> 9.4.0)
1316
- Firebase/CoreOnly (9.4.0):
1417
- FirebaseCore (= 9.4.0)
1518
- Firebase/Crashlytics (9.4.0):
1619
- Firebase/CoreOnly
1720
- FirebaseCrashlytics (~> 9.4.0)
21+
- FirebaseAnalytics/WithoutAdIdSupport (9.4.0):
22+
- FirebaseCore (~> 9.0)
23+
- FirebaseInstallations (~> 9.0)
24+
- GoogleAppMeasurement/WithoutAdIdSupport (= 9.4.0)
25+
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
26+
- GoogleUtilities/MethodSwizzler (~> 7.7)
27+
- GoogleUtilities/Network (~> 7.7)
28+
- "GoogleUtilities/NSData+zlib (~> 7.7)"
29+
- nanopb (< 2.30910.0, >= 2.30908.0)
1830
- FirebaseCore (9.4.0):
1931
- FirebaseCoreDiagnostics (~> 9.0)
2032
- FirebaseCoreInternal (~> 9.0)
@@ -39,27 +51,55 @@ PODS:
3951
- GoogleUtilities/Environment (~> 7.7)
4052
- GoogleUtilities/UserDefaults (~> 7.7)
4153
- PromisesObjC (~> 2.1)
42-
- GoogleDataTransport (9.2.5):
43-
- GoogleUtilities/Environment (~> 7.7)
54+
- GoogleAppMeasurement/WithoutAdIdSupport (9.4.0):
55+
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
56+
- GoogleUtilities/MethodSwizzler (~> 7.7)
57+
- GoogleUtilities/Network (~> 7.7)
58+
- "GoogleUtilities/NSData+zlib (~> 7.7)"
4459
- nanopb (< 2.30910.0, >= 2.30908.0)
60+
- GoogleDataTransport (9.4.1):
61+
- GoogleUtilities/Environment (~> 7.7)
62+
- nanopb (< 2.30911.0, >= 2.30908.0)
4563
- PromisesObjC (< 3.0, >= 1.2)
46-
- GoogleUtilities/Environment (7.11.5):
64+
- GoogleUtilities/AppDelegateSwizzler (7.13.3):
65+
- GoogleUtilities/Environment
66+
- GoogleUtilities/Logger
67+
- GoogleUtilities/Network
68+
- GoogleUtilities/Privacy
69+
- GoogleUtilities/Environment (7.13.3):
70+
- GoogleUtilities/Privacy
4771
- PromisesObjC (< 3.0, >= 1.2)
48-
- GoogleUtilities/Logger (7.11.5):
72+
- GoogleUtilities/Logger (7.13.3):
4973
- GoogleUtilities/Environment
50-
- "GoogleUtilities/NSData+zlib (7.11.5)"
51-
- GoogleUtilities/UserDefaults (7.11.5):
74+
- GoogleUtilities/Privacy
75+
- GoogleUtilities/MethodSwizzler (7.13.3):
76+
- GoogleUtilities/Logger
77+
- GoogleUtilities/Privacy
78+
- GoogleUtilities/Network (7.13.3):
79+
- GoogleUtilities/Logger
80+
- "GoogleUtilities/NSData+zlib"
81+
- GoogleUtilities/Privacy
82+
- GoogleUtilities/Reachability
83+
- "GoogleUtilities/NSData+zlib (7.13.3)":
84+
- GoogleUtilities/Privacy
85+
- GoogleUtilities/Privacy (7.13.3)
86+
- GoogleUtilities/Reachability (7.13.3):
87+
- GoogleUtilities/Logger
88+
- GoogleUtilities/Privacy
89+
- GoogleUtilities/UserDefaults (7.13.3):
5290
- GoogleUtilities/Logger
91+
- GoogleUtilities/Privacy
5392
- GRDB.swift/SQLCipher (6.20.2):
5493
- SQLCipher (>= 3.4.2)
5594
- Instabug (13.3.0)
56-
- nanopb (2.30909.0):
57-
- nanopb/decode (= 2.30909.0)
58-
- nanopb/encode (= 2.30909.0)
59-
- nanopb/decode (2.30909.0)
60-
- nanopb/encode (2.30909.0)
95+
- nanopb (2.30909.1):
96+
- nanopb/decode (= 2.30909.1)
97+
- nanopb/encode (= 2.30909.1)
98+
- nanopb/decode (2.30909.1)
99+
- nanopb/encode (2.30909.1)
61100
- OktaAnalytics (2.0.4):
62101
- AppCenter (~> 5)
102+
- Firebase/AnalyticsWithoutAdIdSupport
63103
- OktaLogger/Core (~> 1)
64104
- OktaSQLiteStorage (~> 0.0.4)
65105
- OktaLogger (1.3.19):
@@ -81,7 +121,7 @@ PODS:
81121
- OktaSQLiteStorage (0.0.5):
82122
- GRDB.swift/SQLCipher (= 6.20.2)
83123
- SQLCipher (= 4.5.5)
84-
- PromisesObjC (2.3.1)
124+
- PromisesObjC (2.4.0)
85125
- SQLCipher (4.5.5):
86126
- SQLCipher/standard (= 4.5.5)
87127
- SQLCipher/common (4.5.5)
@@ -92,6 +132,7 @@ PODS:
92132
DEPENDENCIES:
93133
- AppCenter (~> 5.0.0)
94134
- CocoaLumberjack/Swift (~> 3.6.0)
135+
- Firebase/AnalyticsWithoutAdIdSupport
95136
- Firebase/Crashlytics (~> 9.4.0)
96137
- GRDB.swift/SQLCipher (= 6.20.2)
97138
- Instabug (= 13.3.0)
@@ -107,11 +148,13 @@ SPEC REPOS:
107148
- AppCenter
108149
- CocoaLumberjack
109150
- Firebase
151+
- FirebaseAnalytics
110152
- FirebaseCore
111153
- FirebaseCoreDiagnostics
112154
- FirebaseCoreInternal
113155
- FirebaseCrashlytics
114156
- FirebaseInstallations
157+
- GoogleAppMeasurement
115158
- GoogleDataTransport
116159
- GoogleUtilities
117160
- GRDB.swift
@@ -130,26 +173,28 @@ EXTERNAL SOURCES:
130173
:path: "."
131174

132175
SPEC CHECKSUMS:
133-
AppCenter: 85c92db0759d2792a65eb61d6842d2e86611a49a
176+
AppCenter: 994875ea7941b9e168babb98299f900a94bcef13
134177
CocoaLumberjack: bd155f2dd06c0e0b03f876f7a3ee55693122ec94
135178
Firebase: 7703fc4022824b6d6db1bf7bea58d13b8e17ec46
179+
FirebaseAnalytics: a1a24e72b7ba7f47045a4633f1abb545c07bd29c
136180
FirebaseCore: 9a2b10270a854731c4d4d8a97d0aa8380ec3458d
137181
FirebaseCoreDiagnostics: 99a495094b10a57eeb3ae8efa1665700ad0bdaa6
138182
FirebaseCoreInternal: bca76517fe1ed381e989f5e7d8abb0da8d85bed3
139183
FirebaseCrashlytics: 121ea1d37f4906c94c4c9307297af5121b98b789
140184
FirebaseInstallations: 0a115432c4e223c5ab20b0dbbe4cbefa793a0e8e
141-
GoogleDataTransport: 54dee9d48d14580407f8f5fbf2f496e92437a2f2
142-
GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084
185+
GoogleAppMeasurement: 5d69e04287fc2c10cc43724bfa4bf31fc12c3dff
186+
GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a
187+
GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15
143188
GRDB.swift: 3eb7447131d897afb420d6877a45fd8bfca313c1
144189
Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa
145-
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
146-
OktaAnalytics: 5ce95139d4a7bdcfe89df8f5a5132fc0fe5505c0
190+
nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5
191+
OktaAnalytics: 8e720181e3fd148b2af29a6c3292cb240719a247
147192
OktaLogger: 26fd2a28ab9feb06291cc13a7207d7c8635ed0d6
148193
OktaSQLiteStorage: 4761bb59ed2d6fc2ba6184a4fdd79f2fbeadc50c
149-
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
194+
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
150195
SQLCipher: f2e96b3822e3006b379181a0e4fd145f6de29b56
151196
SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
152197

153-
PODFILE CHECKSUM: b5606fd74aae580c6990d3df9493058ba982af97
198+
PODFILE CHECKSUM: 93a0073cc8b074d7ea487afb97158a9ccbc6d93b
154199

155200
COCOAPODS: 1.15.2

Sources/OktaAnalytics/AnalyticsProviderProtocol.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ import OktaLogger
2020
public protocol AnalyticsProviderProtocol: AnyObject {
2121

2222
/// The name of the provider, e.g. Firebase, AppCenter, etc.
23-
var name: String { get set }
23+
var name: String { get }
24+
25+
/// The default properties that are posted with all events
26+
var defaultProperties: Properties { get }
2427

2528
/// The logger to post logs on its destination
26-
var logger: OktaLoggerProtocol? { get set }
29+
var logger: OktaLoggerProtocol? { get }
2730

28-
/// The default properties that are posted with all events
29-
var defaultProperties: Properties { get set }
31+
/// - Parameters:
32+
/// - name: The name of the provider, e.g. Firebase, AppCenter, etc.
33+
/// - defaultProperties: The default properties that are posted with all events
34+
/// - logger: The logger to post logs on its destination
35+
init(name: String, defaultProperties: Properties, logger: OktaLoggerProtocol?)
3036

3137
/// Tracks an event to the provider
3238
func trackEvent(_ eventName: Name, withProperties: Properties)

Sources/OktaAnalytics/AppCenterAnalyticsProvider.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,20 @@ public class AppCenterAnalyticsProvider: NSObject, AnalyticsProviderProtocol {
1919

2020
// MARK: - Properties
2121

22-
public var defaultProperties: [String: String]?
23-
public var name: String
24-
public var logger: OktaLoggerProtocol?
22+
public let defaultProperties: [String: String]?
23+
public let name: String
24+
public let logger: OktaLoggerProtocol?
2525

2626
private var appCenter: AppCenterAnalytics.Analytics.Type = AppCenterAnalytics.Analytics.self
2727
private var isServicesStarted = false
2828

2929
// MARK: - Initializer
3030
/**
3131
Initializes an instance of `AppCenterAnalyticsProvider`.
32-
33-
- Parameters:
34-
- name: The name of the provider.
35-
- logger: An optional logger to use for logging events.
36-
- appCenter: An optional instance of `AppCenterAnalytics.Analytics.Type`.
3732
*/
38-
public init(name: String, logger: OktaLoggerProtocol? = OktaLogger()) {
33+
public required init(name: String, defaultProperties: Properties, logger: OktaLoggerProtocol? = OktaLogger()) {
3934
self.name = name
35+
self.defaultProperties = defaultProperties
4036
self.logger = logger
4137
}
4238

0 commit comments

Comments
 (0)