Skip to content

[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 6 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 @@ -15,7 +15,7 @@
import Firebase

// Verify that the following Firebase Swift APIs can be found.
import FirebaseAnalyticsSwift
import FirebaseAnalytics
import FirebaseFirestoreSwift
import FirebaseInAppMessaging
import UIKit
Expand Down
1 change: 0 additions & 1 deletion CoreOnly/Tests/FirebasePodTest/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ target 'FirebasePodTest' do

pod 'Firebase', :path => '../../../'
pod 'FirebaseABTesting', :path => '../../../'
pod 'FirebaseAnalyticsSwift', :path => '../../../'
pod 'FirebaseAppDistribution', :path => '../../../'
pod 'FirebaseAuth', :path => '../../../'
pod 'FirebaseCore', :path => '../../../'
Expand Down
2 changes: 0 additions & 2 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@ has_license_changes = didModify(["LICENSE"])
## Product directories
@has_analytics_changes = hasChangesIn([
"FirebaseAnalyticsOnDeviceConversionWrapper",
"FirebaseAnalyticsSwift",
"FirebaseAnalyticsWithoutAdIdSupportWrapper",
"FirebaseAnalyticsWrapper"
]) || didModify([
"FirebaseAnalytics.podspec",
"FirebaseAnalyticsSwift.podspec",
"FirebaseAnalyticsOnDeviceConversion.podspec",
"GoogleAppMeasurement.podspec",
"GoogleAppMeasurementOnDeviceConversion.podspec"
Expand Down
113 changes: 111 additions & 2 deletions FirebaseAnalytics/README.md
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

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.
2 changes: 2 additions & 0 deletions FirebaseAnalytics/Sources/README.md
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.
60 changes: 0 additions & 60 deletions FirebaseAnalyticsSwift.podspec

This file was deleted.

18 changes: 0 additions & 18 deletions FirebaseAnalyticsSwift/CHANGELOG.md

This file was deleted.

111 changes: 0 additions & 111 deletions FirebaseAnalyticsSwift/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions FirebaseAnalyticsSwift/Sources/FirebaseAnalyticsSwift.swift

This file was deleted.

1 change: 0 additions & 1 deletion FirebaseRemoteConfigSwift/Apps/SwiftUISample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ target 'SwiftUISample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'FirebaseAnalytics'
pod 'FirebaseAnalyticsSwift'
pod 'FirebaseCore', :path => '../../../'
pod 'FirebaseCoreInternal', :path => '../../../'
pod 'FirebaseInstallations', :path => '../../../'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import FirebaseAnalytics
import FirebaseAnalyticsSwift
import FirebaseRemoteConfig
import FirebaseRemoteConfigSwift
import SwiftUI
Expand Down
Loading
Loading