Giờ đây, khi đã triển khai hệ thống xác thực để thu thập email hoặc số điện thoại của người dùng, bạn có thể bắt đầu tích hợp Google Analytics cho SDK Firebase.
Tích hợp Google Analytics cho SDK Firebase
Tích hợp với Google Analytics mới nhất cho phiên bản SDK Firebase.
Sử dụng Cocoapods
Nếu ứng dụng của bạn sử dụng Cocoapods, hãy đảm bảo rằng Podfile của dự án chứa:
pod 'FirebaseAnalytics` # includes GoogleAdsOnDeviceConversion
hoặc
pod 'FirebaseAnalytics/Core'
pod 'GoogleAdsOnDeviceConversion'
Sau đó, hãy chạy các lệnh pod repo update và pod install.
Sử dụng Trình quản lý gói Swift
Nếu ứng dụng của bạn sử dụng Trình quản lý gói Swift, hãy làm theo các bước tại Trình quản lý gói Swift cho Firebase.
Khi bạn đến bước "Chọn thư viện Firebase mà bạn muốn đưa vào ứng dụng", hãy đánh dấu vào FirebaseAnalytics trước khi tiếp tục các bước tiếp theo.
Ngoài ra, hãy kiểm tra FirebaseAnalytics/CorevàGoogleAdsOnDeviceConversion.
Tích hợp thay thế
Nếu ứng dụng của bạn không sử dụng Cocoapods hoặc Trình quản lý gói Swift, hãy tích hợp như sau:
Làm theo hướng dẫn README trong tệp zip công khai để thêm trực tiếp các khung vào dự án. Hãy nhớ thêm các khung từ thư mục FirebaseAnalytics.
Trong Xcode, hãy thêm cờ -ObjC và -lc++ vào "Other Linker Settings" (Chế độ cài đặt trình liên kết khác) trong chế độ cài đặt bản dựng của mục tiêu ứng dụng.
Chọn nền tảng iOS tại File (Tệp) > Build Settings (Cài đặt bản dựng), sau đó nhấp vào Build and Run (Tạo và chạy).
Trong thư mục bản dựng được tạo, hãy tìm Podfile và thêm nội dung sau:
pod 'GoogleAdsOnDeviceConversion'
Bật chế độ gỡ lỗi (không bắt buộc)
Bật chế độ gỡ lỗi bằng cách thêm -FIRDebugEnabled vào phần "Arguments Passed on Launch" (Đối số được truyền khi khởi chạy) trong trình chỉnh sửa giao thức của Xcode. Khi khởi chạy ứng dụng trong Xcode, hãy đảm bảo rằng một thông báo như sau xuất hiện trong bảng điều khiển gỡ lỗi Xcode:
[Firebase/Analytics][I-ACS023007] Analytics v.x.x.x started
...
[Firebase/Analytics][I-ACS023009] Debug logging enabled
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[],[],null,["Step 2: Integrate Google Analytics\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------|\n| Introduction: [Measure iOS Ads conversions](/docs/tutorials/ads-ios-on-device-measurement/index-first-party) |\n| Step 1: [Implement a sign-in experience](/docs/tutorials/ads-ios-on-device-measurement/step-1) \u003cbr /\u003e |\n| **Step 2: Integrate Google Analytics** \u003cbr /\u003e |\n| Step 3: [Initiate on-device conversion measurement using Google Analytics](/docs/tutorials/ads-ios-on-device-measurement/step-3) |\n| Step 4: [Troubleshoot and handle common issues](/docs/tutorials/ads-ios-on-device-measurement/step-4) |\n\n\u003cbr /\u003e\n\nNow that you've implemented an authentication system to collect users' emails\nor phone numbers, you can begin integrating the Google Analytics for\nFirebase SDK.\n\nIntegrate the Google Analytics for Firebase SDK\n\nIntegrate with the latest Google Analytics for Firebase SDK version.\n| **Note:** `GoogleAdsOnDeviceConversion` is not subject to [Apple's privacy manifest requirements](https://developer.apple.com/news/?id=3d8a9yyh) and does not include a privacy manifest. No additional action is required to enable on-device conversion measurement.\n\nUse Cocoapods\n\nIf your app uses Cocoapods, ensure your project's Podfile contains either: \n\n pod 'FirebaseAnalytics` # includes GoogleAdsOnDeviceConversion\n\nor \n\n pod 'FirebaseAnalytics/Core'\n pod 'GoogleAdsOnDeviceConversion'\n\nThen, run the commands `pod repo update` and `pod install`.\n\nUse Swift Package Manager\n\nIf your app uses Swift Package Manager, follow the steps at\n[Swift Package Manager for Firebase](/docs/ios/installation-methods#swift-package-manager).\nWhen you reach the step \"Choose the Firebase libraries that you want include in\nyour app\", check `FirebaseAnalytics` before continuing to the next steps.\nAlternatively, check `FirebaseAnalytics/Core` *and*\n`GoogleAdsOnDeviceConversion`.\n\nAlternative integration\n\nIf your app does not use Cocoapods or Swift Package Manager, integrate as\nfollows:\n\n1. Download the public zip file of Firebase from the [firebase-ios-sdk GitHub repo](https://github.com/firebase/firebase-ios-sdk/releases).\n2. Follow the README instructions from the public zip file to add the frameworks to the project directly. Be sure to add the frameworks from the `FirebaseAnalytics` directory.\n3. In Xcode, add the `-ObjC` and `-lc++` flags to \"Other Linker Settings\" in your app target's build settings.\n\nUnity\n\n1. Add the [Firebase Unity SDK](/download/unity)\n (specifically, `FirebaseAnalytics.unitypackage`) to your Unity project. More detailed instructions can be found in [Add Firebase Unity SDKs](https://firebase.google.com/docs/unity/setup#add-sdks).\n\n2. Select the platform iOS at **File** \\\u003e **Build Settings** , then click\n **Build and Run**.\n\n3. In the generated build folder, locate the Podfile and add the following:\n\n pod 'GoogleAdsOnDeviceConversion'\n\nEnable debug mode (optional)\n\nEnable debug mode by adding `-FIRDebugEnabled` under \"Arguments Passed on Launch\"\nin Xcode's scheme editor. Upon launching the app in Xcode, ensure that a\nmessage like the following appears in the Xcode debug console: \n\n [Firebase/Analytics][I-ACS023007] Analytics v.x.x.x started\n ...\n [Firebase/Analytics][I-ACS023009] Debug logging enabled\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\n\u003cbr /\u003e\n\n[arrow_back_ios**Step 1**: Implement a sign-in experience](/docs/tutorials/ads-ios-on-device-measurement/step-1)\n[**Step 3** : Initiate measurements using Google Analyticsarrow_forward_ios](/docs/tutorials/ads-ios-on-device-measurement/step-3)\n\n\u003cbr /\u003e\n\n*** ** * ** ***"]]