Skip to content

Commit 926b678

Browse files
authored
[Analytics] Remove AnalyticsSwift (#13056)
1 parent 8136158 commit 926b678

File tree

22 files changed

+118
-287
lines changed

22 files changed

+118
-287
lines changed

CoreOnly/Tests/FirebasePodTest/FirebasePodTest/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Firebase
1616

1717
// Verify that the following Firebase Swift APIs can be found.
18-
import FirebaseAnalyticsSwift
18+
import FirebaseAnalytics
1919
import FirebaseFirestoreSwift
2020
import FirebaseInAppMessaging
2121
import UIKit

CoreOnly/Tests/FirebasePodTest/Podfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ target 'FirebasePodTest' do
1111

1212
pod 'Firebase', :path => '../../../'
1313
pod 'FirebaseABTesting', :path => '../../../'
14-
pod 'FirebaseAnalyticsSwift', :path => '../../../'
1514
pod 'FirebaseAppDistribution', :path => '../../../'
1615
pod 'FirebaseAuth', :path => '../../../'
1716
pod 'FirebaseCore', :path => '../../../'

Dangerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,10 @@ has_license_changes = didModify(["LICENSE"])
108108
## Product directories
109109
@has_analytics_changes = hasChangesIn([
110110
"FirebaseAnalyticsOnDeviceConversionWrapper",
111-
"FirebaseAnalyticsSwift",
112111
"FirebaseAnalyticsWithoutAdIdSupportWrapper",
113112
"FirebaseAnalyticsWrapper"
114113
]) || didModify([
115114
"FirebaseAnalytics.podspec",
116-
"FirebaseAnalyticsSwift.podspec",
117115
"FirebaseAnalyticsOnDeviceConversion.podspec",
118116
"GoogleAppMeasurement.podspec",
119117
"GoogleAppMeasurementOnDeviceConversion.podspec"

FirebaseAnalytics/README.md

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,111 @@
1-
This directory open sources select files from the Firebase Analytics SDK. Note
2-
that there is no open source infrastructure to build or package them.
1+
# Firebase Analytics SDK
2+
3+
Introduce a manual screen view event logging API that enable developers to log individual views in SwiftUI lifecycle.
4+
5+
## Code Samples
6+
7+
### Before
8+
```swift
9+
10+
struct ContentView: View {
11+
var body: some View {
12+
Text("Hello, world!")
13+
// Logging screen name with class and a custom parameter.
14+
.onAppear {
15+
Analytics.logEvent(AnalyticsEventScreenView,
16+
parameters: [AnalyticsParameterScreenName: "main_content",
17+
AnalyticsParameterScreenClass: "ContentView",
18+
"my_custom_param": 5])
19+
}
20+
21+
// OR Logging screen name only.
22+
.onAppear {
23+
Analytics.logEvent(AnalyticsEventScreenView,
24+
parameters: [AnalyticsParameterScreenName: "main_content"])
25+
}
26+
}
27+
}
28+
29+
```
30+
31+
### After
32+
```swift
33+
struct ContentView: View {
34+
var body: some View {
35+
Text("Hello, world!")
36+
// Logging screen name with class and a custom parameter.
37+
.analyticsScreen(name: "main_content",
38+
class: "ContentView",
39+
extraParameters: ["my_custom_param": 5])
40+
41+
// OR Logging screen name only, class and extra parameters are optional.
42+
.analyticsScreen(name: "main_content")
43+
}
44+
}
45+
```
46+
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.
47+
48+
### Before (Without APIs)
49+
50+
```swift
51+
struct ContentView: View {
52+
var body: some View {
53+
VStack {
54+
Text("Welcome to our App!")
55+
.padding()
56+
Button("Click Me!") {
57+
// Logging a custom event when the button is clicked.
58+
Analytics.logEvent("button_clicked", parameters: nil)
59+
}
60+
}
61+
.onAppear {
62+
// Logging the screen view event when the ContentView appears.
63+
Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: "main_content"])
64+
}
65+
}
66+
}
67+
```
68+
69+
### After (With APIs)
70+
71+
```swift
72+
struct ContentView: View {
73+
var body: some View {
74+
VStack {
75+
Text("Welcome to our App!")
76+
.padding()
77+
Button("Click Me!") {
78+
// Directly using Firebase's logEvent method to log the button click.
79+
Analytics.logEvent("button_clicked", parameters: nil)
80+
}
81+
}
82+
// Using the new manual screen view event logging API to log the screen view.
83+
.analyticsScreen(name: "main_content")
84+
}
85+
}
86+
87+
88+
// Introducing a manual screen view event logging API.
89+
extension View {
90+
func analyticsScreen(name: String, class screenClass: String? = nil, extraParameters: [String: Any]? = nil) -> some View {
91+
onAppear {
92+
var params: [String: Any] = [AnalyticsParameterScreenName: name]
93+
if let screenClass {
94+
params[AnalyticsParameterScreenClass] = screenClass
95+
}
96+
if let extraParameters {
97+
params.merge(extraParameters) { _, new in new }
98+
}
99+
Analytics.logEvent(AnalyticsEventScreenView, parameters: params)
100+
}
101+
}
102+
}
103+
```
104+
105+
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:
106+
107+
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
108+
app. This redundancy made the codebase less efficient and harder to maintain.
109+
110+
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
111+
approach improves the overall code efficiency and enhances code readability.

FirebaseAnalytics/Sources/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory open sources select files from the Firebase Analytics SDK. Note
2+
that there is no open source infrastructure to build or package them.

FirebaseAnalyticsSwift/Tests/SwiftUnit/AnalyticsAPITests.swift renamed to FirebaseAnalytics/Tests/SwiftUnit/AnalyticsAPITests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import StoreKit
2121
import SwiftUI
2222

2323
import FirebaseAnalytics
24-
import FirebaseAnalyticsSwift
2524
import SwiftUI
2625

2726
final class AnalyticsAPITests {

FirebaseAnalyticsSwift.podspec

Lines changed: 0 additions & 60 deletions
This file was deleted.

FirebaseAnalyticsSwift/CHANGELOG.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)