-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Analytics] Remove AnalyticsSwift #13056
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7c3a09
Move stuff out of FirebaseAnalyticsSwift dir
ncooke3 936a5be
Move pt 2
ncooke3 c26a991
Remove or rename FirebaseAnalyticsSwift where needed
ncooke3 8422ef6
Review
ncooke3 f77e21d
Remove 'SwiftPM-PlatformExclude/FirebaseAnalyticsSwiftWrap' directory
ncooke3 7ae4a22
Remove import that's breaking ci
ncooke3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,111 @@ | ||
This directory open sources select files from the Firebase Analytics SDK. Note | ||
that there is no open source infrastructure to build or package them. | ||
# Firebase Analytics Swift SDK | ||
|
||
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Introduce a manual screen view event logging API that enable developers to log individual views in SwiftUI lifecycle. | ||
|
||
## Code Samples | ||
|
||
### Before | ||
```swift | ||
|
||
struct ContentView: View { | ||
var body: some View { | ||
Text("Hello, world!") | ||
// Logging screen name with class and a custom parameter. | ||
.onAppear { | ||
Analytics.logEvent(AnalyticsEventScreenView, | ||
parameters: [AnalyticsParameterScreenName: "main_content", | ||
AnalyticsParameterScreenClass: "ContentView", | ||
"my_custom_param": 5]) | ||
} | ||
|
||
// OR Logging screen name only. | ||
.onAppear { | ||
Analytics.logEvent(AnalyticsEventScreenView, | ||
parameters: [AnalyticsParameterScreenName: "main_content"]) | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
||
### After | ||
```swift | ||
struct ContentView: View { | ||
var body: some View { | ||
Text("Hello, world!") | ||
// Logging screen name with class and a custom parameter. | ||
.analyticsScreen(name: "main_content", | ||
class: "ContentView", | ||
extraParameters: ["my_custom_param": 5]) | ||
|
||
// OR Logging screen name only, class and extra parameters are optional. | ||
.analyticsScreen(name: "main_content") | ||
} | ||
} | ||
``` | ||
An example that demonstrates how the custom event logging API and manual screen view event logging API can make the code more efficient and reduce the number of lines required for event logging. | ||
|
||
### Before (Without APIs) | ||
|
||
```swift | ||
struct ContentView: View { | ||
var body: some View { | ||
VStack { | ||
Text("Welcome to our App!") | ||
.padding() | ||
Button("Click Me!") { | ||
// Logging a custom event when the button is clicked. | ||
Analytics.logEvent("button_clicked", parameters: nil) | ||
} | ||
} | ||
.onAppear { | ||
// Logging the screen view event when the ContentView appears. | ||
Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: "main_content"]) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### After (With APIs) | ||
|
||
```swift | ||
struct ContentView: View { | ||
var body: some View { | ||
VStack { | ||
Text("Welcome to our App!") | ||
.padding() | ||
Button("Click Me!") { | ||
// Directly using Firebase's logEvent method to log the button click. | ||
Analytics.logEvent("button_clicked", parameters: nil) | ||
} | ||
} | ||
// Using the new manual screen view event logging API to log the screen view. | ||
.analyticsScreen(name: "main_content") | ||
} | ||
} | ||
|
||
|
||
// Introducing a manual screen view event logging API. | ||
extension View { | ||
func analyticsScreen(name: String, class screenClass: String? = nil, extraParameters: [String: Any]? = nil) -> some View { | ||
onAppear { | ||
var params: [String: Any] = [AnalyticsParameterScreenName: name] | ||
if let screenClass { | ||
params[AnalyticsParameterScreenClass] = screenClass | ||
} | ||
if let extraParameters { | ||
params.merge(extraParameters) { _, new in new } | ||
} | ||
Analytics.logEvent(AnalyticsEventScreenView, parameters: params) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
In this example, by leveraging the custom event logging API and manual screen view event logging API, we achieve a significant reduction in code complexity for event tracking: | ||
|
||
1. **Before:** In the previous implementation, event logging for button clicks and screen views required separate blocks of code, leading to redundant lines of code throughout the | ||
app. This redundancy made the codebase less efficient and harder to maintain. | ||
|
||
2. **After:** By adopting the event logging API and manual screen view event logging API, we now condense the event tracking logic into just a few lines of code. This streamlined | ||
approach improves the overall code efficiency and enhances code readability. |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This directory open sources select files from the Firebase Analytics SDK. Note | ||
that there is no open source infrastructure to build or package them. |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
FirebaseAnalyticsSwift/Sources/FirebaseAnalyticsSwift.swift
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.