From 1883c2bd5eca5bc58d956eac6f7f5bc48b451ab1 Mon Sep 17 00:00:00 2001 From: Nick Cooke <36927374+ncooke3@users.noreply.github.com> Date: Wed, 18 Oct 2023 08:19:27 -0400 Subject: [PATCH] [Analytics] Consolidate Analytics and AnalyticsSwift (#11959) --- .github/workflows/analytics.yml | 2 +- .github/workflows/client_app.yml | 5 +- .../Analytics+SwiftUI.swift | 0 FirebaseAnalytics/README.md | 2 + FirebaseAnalyticsSwift.podspec | 2 +- FirebaseAnalyticsSwift/CHANGELOG.md | 7 ++ .../Sources/FirebaseAnalyticsSwift.swift | 17 +++++ .../Tests/SwiftUnit/AnalyticsAPITests.swift | 66 ++++++++++--------- .../FirebaseManifest/FirebaseManifest.swift | 2 +- 9 files changed, 67 insertions(+), 36 deletions(-) rename {FirebaseAnalyticsSwift/Sources => FirebaseAnalytics}/Analytics+SwiftUI.swift (100%) create mode 100644 FirebaseAnalytics/README.md create mode 100644 FirebaseAnalyticsSwift/Sources/FirebaseAnalyticsSwift.swift diff --git a/.github/workflows/analytics.yml b/.github/workflows/analytics.yml index a6c92c96dc5..3b3e14fa235 100644 --- a/.github/workflows/analytics.yml +++ b/.github/workflows/analytics.yml @@ -35,7 +35,7 @@ jobs: - name: FirebaseAnalytics run: scripts/third_party/travis/retry.sh pod spec lint FirebaseAnalytics.podspec --platforms=${{ matrix.target }} --sources=https://github.com/firebase/SpecsDev.git,https://github.com/firebase/SpecsStaging.git,https://cdn.cocoapods.org/ - name: FirebaseAnalyticsSwift - run: scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseAnalyticsSwift.podspec --platforms=${{ matrix.target }} + run: scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseAnalyticsSwift.podspec --allow-warnings --platforms=${{ matrix.target }} # The following steps are only run on `ios` due to product availability. - name: GoogleAppMeasurementOnDeviceConversion run: scripts/third_party/travis/retry.sh pod spec lint GoogleAppMeasurementOnDeviceConversion.podspec --platforms=ios --sources=https://github.com/firebase/SpecsDev.git,https://github.com/firebase/SpecsStaging.git,https://cdn.cocoapods.org/ diff --git a/.github/workflows/client_app.yml b/.github/workflows/client_app.yml index 92fcb132860..8a63ae9039d 100644 --- a/.github/workflows/client_app.yml +++ b/.github/workflows/client_app.yml @@ -15,6 +15,9 @@ on: # Run every day at 12am (PST) - cron uses UTC times - cron: "0 8 * * *" +env: + FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1 + concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true @@ -22,8 +25,6 @@ concurrency: jobs: client-app-spm: if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request' - env: - FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1 runs-on: macos-12 strategy: matrix: diff --git a/FirebaseAnalyticsSwift/Sources/Analytics+SwiftUI.swift b/FirebaseAnalytics/Analytics+SwiftUI.swift similarity index 100% rename from FirebaseAnalyticsSwift/Sources/Analytics+SwiftUI.swift rename to FirebaseAnalytics/Analytics+SwiftUI.swift diff --git a/FirebaseAnalytics/README.md b/FirebaseAnalytics/README.md new file mode 100644 index 00000000000..060e06d6cc6 --- /dev/null +++ b/FirebaseAnalytics/README.md @@ -0,0 +1,2 @@ +This directory open sources select files from the Firebase Analytics SDK. Note +that there is no open source infastructure to build or package them. diff --git a/FirebaseAnalyticsSwift.podspec b/FirebaseAnalyticsSwift.podspec index e43a6174358..4acb39700e6 100644 --- a/FirebaseAnalyticsSwift.podspec +++ b/FirebaseAnalyticsSwift.podspec @@ -34,7 +34,7 @@ Firebase Analytics is a free, out-of-the-box analytics solution that inspires ac 'FirebaseAnalyticsSwift/Sources/*.swift', ] - s.dependency 'FirebaseAnalytics', '~> 10.0' + s.dependency 'FirebaseAnalytics', '~> 10.17' s.test_spec 'swift-unit' do |swift_unit_tests| swift_unit_tests.platforms = { diff --git a/FirebaseAnalyticsSwift/CHANGELOG.md b/FirebaseAnalyticsSwift/CHANGELOG.md index b30386d566c..2630b7d1dfb 100644 --- a/FirebaseAnalyticsSwift/CHANGELOG.md +++ b/FirebaseAnalyticsSwift/CHANGELOG.md @@ -1,3 +1,10 @@ +# 10.17.0 +- [deprecated] All of the public API from `FirebaseAnalyticsSwift` can now + be accessed through the `FirebaseAnalytics` module. Therefore, + `FirebaseAnalyticsSwift` has been deprecated, and will be removed in a + future release. See https://firebase.google.com/docs/ios/swift-migration for + migration instructions. + # 9.0.0 - [added] **Breaking change:** `FirebaseAnalyticsSwift` has exited beta and is now generally available for use. diff --git a/FirebaseAnalyticsSwift/Sources/FirebaseAnalyticsSwift.swift b/FirebaseAnalyticsSwift/Sources/FirebaseAnalyticsSwift.swift new file mode 100644 index 00000000000..2265ffb90f5 --- /dev/null +++ b/FirebaseAnalyticsSwift/Sources/FirebaseAnalyticsSwift.swift @@ -0,0 +1,17 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#warning( + "All of the public API from `FirebaseAnalyticsSwift` can now be accessed through the `FirebaseAnalytics` module. Therefore, the `FirebaseAnalyticsSwift` module is deprecated and will be removed in the future. See https://firebase.google.com/docs/ios/swift-migration for migration instructions." +) diff --git a/FirebaseAnalyticsSwift/Tests/SwiftUnit/AnalyticsAPITests.swift b/FirebaseAnalyticsSwift/Tests/SwiftUnit/AnalyticsAPITests.swift index 97a1474d56d..e5e31447a8a 100644 --- a/FirebaseAnalyticsSwift/Tests/SwiftUnit/AnalyticsAPITests.swift +++ b/FirebaseAnalyticsSwift/Tests/SwiftUnit/AnalyticsAPITests.swift @@ -19,28 +19,11 @@ import Foundation import SwiftUI -@testable import FirebaseAnalyticsSwift +import FirebaseAnalyticsSwift +import SwiftUI import FirebaseAnalytics final class AnalyticsAPITests { - @available(iOS 13.0, *) - func loggedAnalyticsModifierUsage(viewModifier: LoggedAnalyticsModifier, - content: LoggedAnalyticsModifier.Content) { - let _: String = viewModifier.screenName - let _: String = viewModifier.screenClass - let _: [String: Any] = viewModifier.extraParameters - let _: any View = viewModifier.body(content: content) - } - - @available(iOS 13.0, *) - func viewExtensionUsage(viewModifier: LoggedAnalyticsModifier, view: any View) { - let _: any View = view.analyticsScreen( - name: "name", - class: "class", - extraParameters: ["param": 1] - ) - } - func usage() { // MARK: - Analytics @@ -54,24 +37,20 @@ final class AnalyticsAPITests { Analytics.setDefaultEventParameters(["default": 100]) Analytics.sessionID { sessionID, error in } - #if compiler(>=5.5.2) && canImport(_Concurrency) - if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) { - Task { - let _: Int64? = try? await Analytics.sessionID() - } + if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) { + Task { + let _: Int64? = try? await Analytics.sessionID() } - #endif // compiler(>=5.5.2) && canImport(_Concurrency) + } // MARK: - AppDelegate Analytics.handleEvents(forBackgroundURLSession: "session_id", completionHandler: {}) - #if compiler(>=5.5.2) && canImport(_Concurrency) - if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) { - Task { - await Analytics.handleEvents(forBackgroundURLSession: "session_id") - } + if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) { + Task { + await Analytics.handleEvents(forBackgroundURLSession: "session_id") } - #endif // compiler(>=5.5.2) && canImport(_Concurrency) + } Analytics.handleOpen(URL(string: "https://google.com")!) Analytics.handleUserActivity(NSUserActivity(activityType: "editing")) @@ -203,5 +182,30 @@ final class AnalyticsAPITests { AnalyticsUserPropertyAllowAdPersonalizationSignals, AnalyticsUserPropertySignUpMethod, ] + + // MARK: - Analytics + SwiftUI + + @available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) + @available(watchOS, unavailable) + struct MyView: View { + let name: String + let klass: String + let extraParameters: [String: Any] + + var body: some View { + Text("Hello, world!") + .analyticsScreen(name: name, + class: klass, + extraParameters: extraParameters) + Text("Hello, world!") + .analyticsScreen(name: name, + extraParameters: extraParameters) + Text("Hello, world!") + .analyticsScreen(name: name, + class: klass) + Text("Hello, world!") + .analyticsScreen(name: name) + } + } } } diff --git a/ReleaseTooling/Sources/FirebaseManifest/FirebaseManifest.swift b/ReleaseTooling/Sources/FirebaseManifest/FirebaseManifest.swift index af1befcdbe1..8a963bdcd8d 100755 --- a/ReleaseTooling/Sources/FirebaseManifest/FirebaseManifest.swift +++ b/ReleaseTooling/Sources/FirebaseManifest/FirebaseManifest.swift @@ -36,7 +36,7 @@ public let shared = Manifest( Pod("GoogleAppMeasurementOnDeviceConversion", isClosedSource: true, platforms: ["ios"]), Pod("FirebaseAnalytics", isClosedSource: true), Pod("FirebaseAnalyticsOnDeviceConversion", platforms: ["ios"], zip: true), - Pod("FirebaseAnalyticsSwift", zip: true), + Pod("FirebaseAnalyticsSwift", allowWarnings: true, zip: true), Pod("FirebaseABTesting", zip: true), Pod("FirebaseAppCheck", zip: true), Pod("FirebaseRemoteConfig"),