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

Conversation

rnr
Copy link
Contributor

@rnr rnr commented Feb 21, 2024

This PR implements both Analytics options - Firebase+GoogleAnalytics standalone library and Segment+GoogleAnalytics.
In the config we have the ANALYTICS_SOURCE parameter:

FIREBASE:
    ENABLED: true
    ANALYTICS_SOURCE: 'segment'

This parameter may have values:

  • firebase
  • segment

Depending on this parameter, the application uses the appropriate library. For this purpose, FirebaseAnalyticsService and SegmentAnalyticsService are added. Both services are added to the DI.

Comment on lines 21 to 22
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

@@ -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

import Firebase
import Core

class FirebaseAnalyticsManager: AnalyticsService {
Copy link
Contributor

Choose a reason for hiding this comment

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

Although we have collaborated on it and name is also fine, but as it's more like a tracker instead of manager, how about renaming it to FirebaseAnalyticsTracker.

If it sounds good then the same will go for Segment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about FirebaseAnalyticsService?

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

.trackApplicationLifecycleEvents(true)
.flushInterval(10)
analytics = Analytics(configuration: configuration)
if config.firebase.isAnalyticsSourceSegment {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh it got missed, please update condition for config.firebase.enabled as well so in case of missing keys app will not crash.

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

@rnr rnr requested a review from saeedbashir February 22, 2024 11:54
forgotvas
forgotvas previously approved these changes Feb 22, 2024
saeedbashir
saeedbashir previously approved these changes Feb 22, 2024
Copy link
Contributor

@saeedbashir saeedbashir left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Comment on lines -41 to -44
if let configuration = config.firebase.firebaseOptions {
FirebaseApp.configure(options: configuration)
Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(true)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't remove that part of the code, Crashlytics will stop working.

Copy link
Contributor

Choose a reason for hiding this comment

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

@volodymyr-chekyrta We've added FirebaseCrashlyticsCollectionEnabled in the info.plist, I believe this will do the job.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! Got it, let me check it out.

public init(config: ConfigProtocol) {
guard config.firebase.enabled && config.firebase.isAnalyticsSourceFirebase else { return }

FirebaseApp.configure()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we don't have the GoogleServices.plist file to configure Firebase, we have to pass the configuration to the configure function.
https://github.com/openedx/openedx-app-ios/blob/main/OpenEdX/AppDelegate.swift#L42

Copy link
Contributor

Choose a reason for hiding this comment

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

@volodymyr-chekyrta The config processing script is already generating the GoogleService-Info.plist file by reading the values from the config for FIREBASE.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thank you!

@rnr rnr dismissed stale reviews from saeedbashir and forgotvas via 00a6c86 February 26, 2024 09:14
Copy link
Contributor

@volodymyr-chekyrta volodymyr-chekyrta left a comment

Choose a reason for hiding this comment

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

@rnr, LGTM 👍
@saeedbashir, thanks for comments

@rnr rnr merged commit cf65ce9 into openedx:develop Feb 26, 2024
3 checks passed
@rnr rnr deleted the test/segment_plus_firebase branch February 26, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS] Segment SDK Implementation [iOS] Third-party Push Notifications tool SDK integration
4 participants