Skip to content

Commit

Permalink
OKTA-807366: Add firebase Analytics to OktaAnalytics sdk (#102)
Browse files Browse the repository at this point in the history
OKTA-807366: Add firebase Analytics and tests to OktaAnalytics

Add test cases
  • Loading branch information
sandeeppenchala-okta authored Sep 24, 2024
1 parent 3bf5d06 commit 4d05c50
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 48 deletions.
18 changes: 16 additions & 2 deletions Example/Example-iOS/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Firebase
import OktaLogger
import OktaAnalytics
import AppCenterAnalytics
import FirebaseAnalytics

var scenarioID: ScenarioID = ""

Expand All @@ -30,18 +31,31 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
defaultProperties: nil
)
)
let appCenterAnalyticsProvider = AppCenterAnalyticsProvider(name: "AppCenter", logger: logger)
let appCenterAnalyticsProvider = AppCenterAnalyticsProvider(name: "AppCenter", defaultProperties: [:], logger: logger)
appCenterAnalyticsProvider.start(withAppSecret: "App Secret", services: [AppCenterAnalytics.Analytics.self])
return appCenterAnalyticsProvider
}()

let firebaseAnalyticsProvider: AnalyticsProviderProtocol = {
let logger = OktaLogger()
logger.addDestination(
OktaLoggerConsoleLogger(
identifier: "com.okta.loggerDemo.console",
level: OktaLoggerLogLevel.debug,
defaultProperties: nil
)
)
let firebaseAnalyticsProvider = FirebaseAnalyticsProvider(name: "Firebase Analytics", defaultProperties: [:], logger: logger)
return firebaseAnalyticsProvider
}()

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
FirebaseApp.configure()
OktaAnalytics.initializeStorageWith(securityAppGroupIdentifier: Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String ?? "")
OktaAnalytics.addProvider(appCenterAnalyticsProvider)
OktaAnalytics.addProvider(firebaseAnalyticsProvider)
OktaAnalytics.trackEvent("applicationDidFinishLaunchingWithOptions", withProperties: nil)
OktaAnalytics.startScenario(ScenarioEvent(name: "Application", properties: [Property(key: "AppDelegate.application.didFinishLaunchingWithOptions", value: "1")])) {
scenarioID = $0 ?? ""
Expand Down
3 changes: 2 additions & 1 deletion OktaAnalytics.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "OktaAnalytics"
s.version = "2.0.4"
s.version = "2.1"
s.summary = "Implementation of Analytics logger destination"
s.description = "Implementation of Analytics logger destination. Requires OktaLogger/Core"
s.homepage = "https://github.com/okta/okta-logger-swift"
Expand All @@ -18,4 +18,5 @@ Pod::Spec.new do |s|
s.dependency 'AppCenter','~>5'
s.dependency 'OktaLogger/Core', '~>1'
s.dependency 'OktaSQLiteStorage', '~>0.0.4'
s.dependency 'Firebase/AnalyticsWithoutAdIdSupport'
end
8 changes: 6 additions & 2 deletions OktaLogger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
2428E650B877FD5A91A859F9 /* libPods-OktaLoggerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AB97EA576638C766A84A9DCD /* libPods-OktaLoggerTests.a */; };
413B96875EB52EB482005A8F /* libPods-OktaAnalytics.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A254F4CD3A3C59AD6B7B3E8C /* libPods-OktaAnalytics.a */; };
6582A2024047A1BC55BC98D3 /* LumberjackLoggerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6582AABCF4A4B6E5E05FC2E4 /* LumberjackLoggerDelegate.swift */; };
6582A2C33C06B4353D1538E3 /* FileLoggerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6582ABCA2C9C2759535A1B4E /* FileLoggerDelegate.swift */; };
6CCBD40A2C9CC64400E8FEEE /* FirebaseAnalyticsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CCBD4092C9CC63900E8FEEE /* FirebaseAnalyticsProvider.swift */; };
7B13559F276BE69400F0516C /* OktaLoggerFirebaseLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B13559E276BE69400F0516C /* OktaLoggerFirebaseLoggerTests.swift */; };
7FC038A4282467C300C16169 /* OktaLoggerLogLevel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC0389E282467C300C16169 /* OktaLoggerLogLevel.swift */; };
7FC038A5282467C300C16169 /* ReadWriteLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC0389F282467C300C16169 /* ReadWriteLock.swift */; };
Expand Down Expand Up @@ -112,6 +113,7 @@
6582ABCA2C9C2759535A1B4E /* FileLoggerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileLoggerDelegate.swift; sourceTree = "<group>"; };
6C98A0E828A308FD00DA6CA9 /* OktaAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaAnalytics.swift; sourceTree = "<group>"; };
6CAB2C7728DD22750020221F /* AppCenterAnalyticsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCenterAnalyticsProvider.swift; sourceTree = "<group>"; };
6CCBD4092C9CC63900E8FEEE /* FirebaseAnalyticsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseAnalyticsProvider.swift; sourceTree = "<group>"; };
6CD94F5828CEEB2000EE4254 /* AnalyticsProviderProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsProviderProtocol.swift; sourceTree = "<group>"; };
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>"; };
7B13559E276BE69400F0516C /* OktaLoggerFirebaseLoggerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OktaLoggerFirebaseLoggerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -467,8 +469,9 @@
F3575F2D2A0AD1850008A965 /* OktaAnalytics */ = {
isa = PBXGroup;
children = (
6CD94F5828CEEB2000EE4254 /* AnalyticsProviderProtocol.swift */,
6CCBD4092C9CC63900E8FEEE /* FirebaseAnalyticsProvider.swift */,
6CAB2C7728DD22750020221F /* AppCenterAnalyticsProvider.swift */,
6CD94F5828CEEB2000EE4254 /* AnalyticsProviderProtocol.swift */,
6C98A0E828A308FD00DA6CA9 /* OktaAnalytics.swift */,
F3ACE11A29BADB03003C3403 /* Properties.swift */,
F3C091352A1576780015E9FC /* AnalyticsStorage.swift */,
Expand Down Expand Up @@ -1102,6 +1105,7 @@
F3575F492A0AD19A0008A965 /* AnalyticsProviderProtocol.swift in Sources */,
F3575F4F2A0AD1A60008A965 /* OktaAnalytics.swift in Sources */,
F3C091392A15D2080015E9FC /* ReadWriteLock.swift in Sources */,
6CCBD40A2C9CC64400E8FEEE /* FirebaseAnalyticsProvider.swift in Sources */,
F3575F4C2A0AD1A60008A965 /* Properties.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
ReferencedContainer = "container:OktaLogger.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-FIRAnalyticsDebugEnabled"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ target 'OktaAnalytics' do
pod 'OktaSQLiteStorage', :path => '.'
pod 'AppCenter', '~>5.0.0'
pod 'SwiftLint', '0.51'
pod 'Firebase/AnalyticsWithoutAdIdSupport'
end

target 'OktaLoggerDemoApp' do
Expand All @@ -39,4 +40,4 @@ target 'OktaAnalyticsTests' do
pod 'OktaAnalytics', :path => '.'
pod 'OktaSQLiteStorage', :path => '.'
pod 'AppCenter', '~>5.0.0'
end
end
95 changes: 70 additions & 25 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
PODS:
- AppCenter (5.0.4):
- AppCenter/Analytics (= 5.0.4)
- AppCenter/Crashes (= 5.0.4)
- AppCenter/Analytics (5.0.4):
- AppCenter (5.0.5):
- AppCenter/Analytics (= 5.0.5)
- AppCenter/Crashes (= 5.0.5)
- AppCenter/Analytics (5.0.5):
- AppCenter/Core
- AppCenter/Core (5.0.4)
- AppCenter/Crashes (5.0.4):
- AppCenter/Core (5.0.5)
- AppCenter/Crashes (5.0.5):
- AppCenter/Core
- CocoaLumberjack/Core (3.6.2)
- CocoaLumberjack/Swift (3.6.2):
- CocoaLumberjack/Core
- Firebase/AnalyticsWithoutAdIdSupport (9.4.0):
- Firebase/CoreOnly
- FirebaseAnalytics/WithoutAdIdSupport (~> 9.4.0)
- Firebase/CoreOnly (9.4.0):
- FirebaseCore (= 9.4.0)
- Firebase/Crashlytics (9.4.0):
- Firebase/CoreOnly
- FirebaseCrashlytics (~> 9.4.0)
- FirebaseAnalytics/WithoutAdIdSupport (9.4.0):
- FirebaseCore (~> 9.0)
- FirebaseInstallations (~> 9.0)
- GoogleAppMeasurement/WithoutAdIdSupport (= 9.4.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/MethodSwizzler (~> 7.7)
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- FirebaseCore (9.4.0):
- FirebaseCoreDiagnostics (~> 9.0)
- FirebaseCoreInternal (~> 9.0)
Expand All @@ -39,27 +51,55 @@ PODS:
- GoogleUtilities/Environment (~> 7.7)
- GoogleUtilities/UserDefaults (~> 7.7)
- PromisesObjC (~> 2.1)
- GoogleDataTransport (9.2.5):
- GoogleUtilities/Environment (~> 7.7)
- GoogleAppMeasurement/WithoutAdIdSupport (9.4.0):
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/MethodSwizzler (~> 7.7)
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleDataTransport (9.4.1):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30911.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Environment (7.11.5):
- GoogleUtilities/AppDelegateSwizzler (7.13.3):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Privacy
- GoogleUtilities/Environment (7.13.3):
- GoogleUtilities/Privacy
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.11.5):
- GoogleUtilities/Logger (7.13.3):
- GoogleUtilities/Environment
- "GoogleUtilities/NSData+zlib (7.11.5)"
- GoogleUtilities/UserDefaults (7.11.5):
- GoogleUtilities/Privacy
- GoogleUtilities/MethodSwizzler (7.13.3):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilities/Network (7.13.3):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Privacy
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (7.13.3)":
- GoogleUtilities/Privacy
- GoogleUtilities/Privacy (7.13.3)
- GoogleUtilities/Reachability (7.13.3):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilities/UserDefaults (7.13.3):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GRDB.swift/SQLCipher (6.20.2):
- SQLCipher (>= 3.4.2)
- Instabug (13.3.0)
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- nanopb (2.30909.1):
- nanopb/decode (= 2.30909.1)
- nanopb/encode (= 2.30909.1)
- nanopb/decode (2.30909.1)
- nanopb/encode (2.30909.1)
- OktaAnalytics (2.0.4):
- AppCenter (~> 5)
- Firebase/AnalyticsWithoutAdIdSupport
- OktaLogger/Core (~> 1)
- OktaSQLiteStorage (~> 0.0.4)
- OktaLogger (1.3.19):
Expand All @@ -81,7 +121,7 @@ PODS:
- OktaSQLiteStorage (0.0.5):
- GRDB.swift/SQLCipher (= 6.20.2)
- SQLCipher (= 4.5.5)
- PromisesObjC (2.3.1)
- PromisesObjC (2.4.0)
- SQLCipher (4.5.5):
- SQLCipher/standard (= 4.5.5)
- SQLCipher/common (4.5.5)
Expand All @@ -92,6 +132,7 @@ PODS:
DEPENDENCIES:
- AppCenter (~> 5.0.0)
- CocoaLumberjack/Swift (~> 3.6.0)
- Firebase/AnalyticsWithoutAdIdSupport
- Firebase/Crashlytics (~> 9.4.0)
- GRDB.swift/SQLCipher (= 6.20.2)
- Instabug (= 13.3.0)
Expand All @@ -107,11 +148,13 @@ SPEC REPOS:
- AppCenter
- CocoaLumberjack
- Firebase
- FirebaseAnalytics
- FirebaseCore
- FirebaseCoreDiagnostics
- FirebaseCoreInternal
- FirebaseCrashlytics
- FirebaseInstallations
- GoogleAppMeasurement
- GoogleDataTransport
- GoogleUtilities
- GRDB.swift
Expand All @@ -130,26 +173,28 @@ EXTERNAL SOURCES:
:path: "."

SPEC CHECKSUMS:
AppCenter: 85c92db0759d2792a65eb61d6842d2e86611a49a
AppCenter: 994875ea7941b9e168babb98299f900a94bcef13
CocoaLumberjack: bd155f2dd06c0e0b03f876f7a3ee55693122ec94
Firebase: 7703fc4022824b6d6db1bf7bea58d13b8e17ec46
FirebaseAnalytics: a1a24e72b7ba7f47045a4633f1abb545c07bd29c
FirebaseCore: 9a2b10270a854731c4d4d8a97d0aa8380ec3458d
FirebaseCoreDiagnostics: 99a495094b10a57eeb3ae8efa1665700ad0bdaa6
FirebaseCoreInternal: bca76517fe1ed381e989f5e7d8abb0da8d85bed3
FirebaseCrashlytics: 121ea1d37f4906c94c4c9307297af5121b98b789
FirebaseInstallations: 0a115432c4e223c5ab20b0dbbe4cbefa793a0e8e
GoogleDataTransport: 54dee9d48d14580407f8f5fbf2f496e92437a2f2
GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084
GoogleAppMeasurement: 5d69e04287fc2c10cc43724bfa4bf31fc12c3dff
GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a
GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15
GRDB.swift: 3eb7447131d897afb420d6877a45fd8bfca313c1
Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
OktaAnalytics: 5ce95139d4a7bdcfe89df8f5a5132fc0fe5505c0
nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5
OktaAnalytics: 8e720181e3fd148b2af29a6c3292cb240719a247
OktaLogger: 26fd2a28ab9feb06291cc13a7207d7c8635ed0d6
OktaSQLiteStorage: 4761bb59ed2d6fc2ba6184a4fdd79f2fbeadc50c
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
SQLCipher: f2e96b3822e3006b379181a0e4fd145f6de29b56
SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5

PODFILE CHECKSUM: b5606fd74aae580c6990d3df9493058ba982af97
PODFILE CHECKSUM: 93a0073cc8b074d7ea487afb97158a9ccbc6d93b

COCOAPODS: 1.15.2
14 changes: 10 additions & 4 deletions Sources/OktaAnalytics/AnalyticsProviderProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ import OktaLogger
public protocol AnalyticsProviderProtocol: AnyObject {

/// The name of the provider, e.g. Firebase, AppCenter, etc.
var name: String { get set }
var name: String { get }

/// The default properties that are posted with all events
var defaultProperties: Properties { get }

/// The logger to post logs on its destination
var logger: OktaLoggerProtocol? { get set }
var logger: OktaLoggerProtocol? { get }

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

/// Tracks an event to the provider
func trackEvent(_ eventName: Name, withProperties: Properties)
Expand Down
14 changes: 5 additions & 9 deletions Sources/OktaAnalytics/AppCenterAnalyticsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@ public class AppCenterAnalyticsProvider: NSObject, AnalyticsProviderProtocol {

// MARK: - Properties

public var defaultProperties: [String: String]?
public var name: String
public var logger: OktaLoggerProtocol?
public let defaultProperties: [String: String]?
public let name: String
public let logger: OktaLoggerProtocol?

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

// MARK: - Initializer
/**
Initializes an instance of `AppCenterAnalyticsProvider`.
- Parameters:
- name: The name of the provider.
- logger: An optional logger to use for logging events.
- appCenter: An optional instance of `AppCenterAnalytics.Analytics.Type`.
*/
public init(name: String, logger: OktaLoggerProtocol? = OktaLogger()) {
public required init(name: String, defaultProperties: Properties, logger: OktaLoggerProtocol? = OktaLogger()) {
self.name = name
self.defaultProperties = defaultProperties
self.logger = logger
}

Expand Down
Loading

0 comments on commit 4d05c50

Please sign in to comment.