Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase and Segment integration #291

Merged
merged 26 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a6fc40d
chore: added abstract layer for push notifications
rnr Jan 24, 2024
077ae85
Merge pull request #2 from touchapp/push_notifications_abstract
rnr Jan 24, 2024
c87f7cb
chore: abstract layer for deep linking
rnr Jan 26, 2024
3f4049c
chore: test braze experiment
rnr Jan 29, 2024
8bc62e7
chore: added segment package
rnr Feb 2, 2024
2d2ade2
chore: returned back default values
rnr Feb 6, 2024
dfdf6a4
Merge branch 'develop' into test/test_braze
rnr Feb 6, 2024
c164495
chore: added firebase as swift package
rnr Feb 6, 2024
f9c6813
chore: fixed upload crashlytic dsym build phase script
rnr Feb 7, 2024
53f73d5
Merge branch 'develop' into test/segment_plus_firebase
rnr Feb 15, 2024
5a61d28
chore: added AnalyticsService protocol and instances
rnr Feb 15, 2024
5d9dd2b
chore: cleanup code
rnr Feb 15, 2024
c48416c
chore: renamed google analytics to firebase analitics. added checking…
rnr Feb 16, 2024
59b5be7
chore: added FirebaseManager to setup standalone Firebase in separate…
rnr Feb 19, 2024
78a4f3d
chore: moved analytics segment var into SegmentManager
rnr Feb 21, 2024
81984f9
chore: moved AnalyticsService protocol implementation into Firebase a…
rnr Feb 21, 2024
70285cc
chore: moved setup into managers init methods, renamed managers
rnr Feb 21, 2024
17b8ee7
chore: added check if services are enabled while init
rnr Feb 21, 2024
1c4939b
chore: renamed managers group
rnr Feb 21, 2024
5eb6e20
chore: cleanup code
rnr Feb 21, 2024
d5d27ae
Merge branch 'develop' into test/segment_plus_firebase
rnr Feb 21, 2024
af25b64
chore: re-added Segment package through https source
rnr Feb 21, 2024
7c67115
chore: generated mocks
rnr Feb 21, 2024
f40b7f2
refactor: address review feedback, added test for segment config
rnr Feb 22, 2024
00a6c86
Merge branch 'develop' into test/segment_plus_firebase
rnr Feb 26, 2024
fb22073
chore: auto-generated mocks
rnr Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum SocialAuthMethod: String {

//sourcery: AutoMockable
public protocol AuthorizationAnalytics {
func setUserID(_ id: String)
func identify(id: String, username: String, email: String)
func userLogin(method: AuthMethod)
func signUpClicked()
func createAccountClicked()
Expand All @@ -41,7 +41,7 @@ public protocol AuthorizationAnalytics {

#if DEBUG
class AuthorizationAnalyticsMock: AuthorizationAnalytics {
public func setUserID(_ id: String) {}
func identify(id: String, username: String, email: String) {}
public func userLogin(method: AuthMethod) {}
public func signUpClicked() {}
public func createAccountClicked() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class SignInViewModel: ObservableObject {
isShowProgress = true
do {
let user = try await interactor.login(username: username, password: password)
analytics.setUserID("\(user.id)")
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.userLogin(method: .password)
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch let error {
Expand Down Expand Up @@ -110,7 +110,7 @@ public class SignInViewModel: ObservableObject {
isShowProgress = true
do {
let user = try await interactor.login(externalToken: externalToken, backend: backend)
analytics.setUserID("\(user.id)")
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.userLogin(method: authMethod)
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch let error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class SignUpViewModel: ObservableObject {
fields: validateFields,
isSocial: externalToken != nil
)
analytics.setUserID("\(user.id)")
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving the analytics.identify(.....) call to showMainOrWhatsNewScreen so you don't have to worry about from where the main screen is being shown? At the moment it's being called from multiple places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the idea of passing User variable inside the router. However, we may come back to this question when we work with analytics (this is not part of this PR)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

analytics.registrationSuccess()
isShowProgress = false
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
Expand Down Expand Up @@ -188,7 +188,7 @@ public class SignUpViewModel: ObservableObject {
do {
isShowProgress = true
let user = try await interactor.login(externalToken: response.token, backend: backend)
analytics.setUserID("\(user.id)")
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.userLogin(method: authMethod)
isShowProgress = false
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
Expand Down
272 changes: 260 additions & 12 deletions Authorization/AuthorizationTests/AuthorizationMock.generated.swift

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@
07DDFCBD29A780BB00572595 /* UINavigationController+Animation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07DDFCBC29A780BB00572595 /* UINavigationController+Animation.swift */; };
07E0939F2B308D2800F1E4B2 /* Data_Certificate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07E0939E2B308D2800F1E4B2 /* Data_Certificate.swift */; };
141F1D302B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 141F1D2F2B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift */; };
A51CDBE72B6D21F2009B6D4E /* SegmentConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51CDBE62B6D21F2009B6D4E /* SegmentConfig.swift */; };
A53A32352B233DEC005FE38A /* ThemeConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53A32342B233DEC005FE38A /* ThemeConfig.swift */; };
A595689B2B6173DF00ED4F90 /* BranchConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A595689A2B6173DF00ED4F90 /* BranchConfig.swift */; };
A5F4E7B52B61544A00ACD166 /* BrazeConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F4E7B42B61544A00ACD166 /* BrazeConfig.swift */; };
BA30427F2B20B320009B64B7 /* SocialAuthError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA30427D2B20B299009B64B7 /* SocialAuthError.swift */; };
BA4AFB442B6A5AF100A21367 /* CheckBoxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AFB432B6A5AF100A21367 /* CheckBoxView.swift */; };
BA4AFB422B5A7A0900A21367 /* VideoDownloadQualityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AFB412B5A7A0900A21367 /* VideoDownloadQualityView.swift */; };
BA4AFB442B6A5AF100A21367 /* CheckBoxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AFB432B6A5AF100A21367 /* CheckBoxView.swift */; };
BA593F1C2AF8E498009ADB51 /* ScrollSlidingTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA593F1B2AF8E498009ADB51 /* ScrollSlidingTabBar.swift */; };
BA593F1E2AF8E4A0009ADB51 /* FrameReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA593F1D2AF8E4A0009ADB51 /* FrameReader.swift */; };
BA76135C2B21BC7300B599B7 /* SocialAuthResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA76135B2B21BC7300B599B7 /* SocialAuthResponse.swift */; };
Expand Down Expand Up @@ -303,12 +304,13 @@
3B74C6685E416657F3C5F5A8 /* Pods-App-Core.releaseprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.releaseprod.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.releaseprod.xcconfig"; sourceTree = "<group>"; };
60153262DBC2F9E660D7E11B /* Pods-App-Core.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.release.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.release.xcconfig"; sourceTree = "<group>"; };
9D5B06CAA99EA5CD49CBE2BB /* Pods-App-Core.debugdev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debugdev.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debugdev.xcconfig"; sourceTree = "<group>"; };
A51CDBE62B6D21F2009B6D4E /* SegmentConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentConfig.swift; sourceTree = "<group>"; };
A53A32342B233DEC005FE38A /* ThemeConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemeConfig.swift; sourceTree = "<group>"; };
A595689A2B6173DF00ED4F90 /* BranchConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BranchConfig.swift; sourceTree = "<group>"; };
A5F4E7B42B61544A00ACD166 /* BrazeConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrazeConfig.swift; sourceTree = "<group>"; };
BA30427D2B20B299009B64B7 /* SocialAuthError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocialAuthError.swift; sourceTree = "<group>"; };
BA4AFB432B6A5AF100A21367 /* CheckBoxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxView.swift; sourceTree = "<group>"; };
BA4AFB412B5A7A0900A21367 /* VideoDownloadQualityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoDownloadQualityView.swift; sourceTree = "<group>"; };
BA4AFB432B6A5AF100A21367 /* CheckBoxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxView.swift; sourceTree = "<group>"; };
BA593F1B2AF8E498009ADB51 /* ScrollSlidingTabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollSlidingTabBar.swift; sourceTree = "<group>"; };
BA593F1D2AF8E4A0009ADB51 /* FrameReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FrameReader.swift; sourceTree = "<group>"; };
BA76135B2B21BC7300B599B7 /* SocialAuthResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialAuthResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -781,6 +783,7 @@
DBF6F2402B014ADA0098414B /* FirebaseConfig.swift */,
A5F4E7B42B61544A00ACD166 /* BrazeConfig.swift */,
A595689A2B6173DF00ED4F90 /* BranchConfig.swift */,
A51CDBE62B6D21F2009B6D4E /* SegmentConfig.swift */,
DBF6F2492B0380E00098414B /* FeaturesConfig.swift */,
DBF6F2452B01DAFE0098414B /* AgreementConfig.swift */,
BAFB99812B0E2354007D09F9 /* FacebookConfig.swift */,
Expand Down Expand Up @@ -1025,6 +1028,7 @@
02B3E3B32930198600A50475 /* AVPlayerViewControllerExtension.swift in Sources */,
BAD9CA332B28A8F300DE790A /* AjaxProvider.swift in Sources */,
0295C885299B99DD00ABE571 /* RefreshableScrollView.swift in Sources */,
A51CDBE72B6D21F2009B6D4E /* SegmentConfig.swift in Sources */,
0282DA7328F98CC9003C3F07 /* WebUnitView.swift in Sources */,
E0D586362B314CD3009B4BA7 /* LogistrationBottomView.swift in Sources */,
0727878128D25EFD002E9142 /* SnackBarView.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Core/Core/Configuration/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public protocol ConfigProtocol {
var discovery: DiscoveryConfig { get }
var braze: BrazeConfig { get }
var branch: BranchConfig { get }
var segment: SegmentConfig { get }
var program: DiscoveryConfig { get }
var URIScheme: String { get }
}
Expand Down
20 changes: 0 additions & 20 deletions Core/Core/Configuration/Config/FirebaseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import FirebaseCore

private enum FirebaseKeys: String {
case enabled = "ENABLED"
Expand Down Expand Up @@ -76,25 +75,6 @@ public final class FirebaseConfig: NSObject {
public var isAnalyticsSourceFirebase: Bool {
return analyticsSource == AnalyticsSource.firebase
}

public var firebaseOptions: FirebaseOptions? {
if enabled,
requiredKeysAvailable,
let bundleID = bundleID,
let googleAppID = googleAppID,
let gcmSenderID = gcmSenderID {
let firebaseOptions = FirebaseOptions(googleAppID: googleAppID,
gcmSenderID: gcmSenderID)
firebaseOptions.apiKey = apiKey
firebaseOptions.projectID = projectID
firebaseOptions.bundleID = bundleID
firebaseOptions.clientID = clientID
firebaseOptions.storageBucket = storageBucket
firebaseOptions.databaseURL = databaseURL
}

return nil
}
}

private let firebaseKey = "FIREBASE"
Expand Down
31 changes: 31 additions & 0 deletions Core/Core/Configuration/Config/SegmentConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// SegmentConfig.swift
// Core
//
// Created by Anton Yarmolenka on 02/02/2024.
//

import Foundation

private enum SegmentKeys: String, RawStringExtractable {
case enabled = "ENABLED"
case writeKey = "SEGMENT_IO_WRITE_KEY"
}

public final class SegmentConfig: NSObject {
public var enabled: Bool = false
public var writeKey: String = ""

init(dictionary: [String: AnyObject]) {
super.init()
enabled = dictionary[SegmentKeys.enabled] as? Bool == true
writeKey = dictionary[SegmentKeys.writeKey] as? String ?? ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make enabled also dependent on writeKey like the writeKey shouldn't be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

private let segmentKey = "SEGMENT_IO"
extension Config {
public var segment: SegmentConfig {
SegmentConfig(dictionary: self[segmentKey] as? [String: AnyObject] ?? [:])
}
}
Loading