Tích hợp Firebase với dự án trên Dịch vụ trò chơi của Play
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Firebase có thể giúp nâng tầm trò chơi của bạn:
Ghi lại các sự kiện Trò chơi bằng Google Analytics, một giải pháp đo lường ứng dụng miễn phí, cung cấp thông tin chi tiết về mức sử dụng ứng dụng và hoạt động tương tác của người dùng.
Nếu chưa có, hãy tạo một dự án Firebase, sau đó thêm Firebase vào trò chơi của bạn (C++ | Unity).
Liên kết ứng dụng Firebase với Google Playtài khoản nhà phát triển.
Dự án Play Games services của bạn sẽ dùng chính đường liên kết này.
Trong bảng điều khiển Firebase, hãy chuyển đến thẻ Tích hợp.
Trên thẻ Google Play, hãy nhấp vào Liên kết rồi làm theo hướng dẫn trên màn hình để tạo đường liên kết.
Sau khi thêm Firebase SDK cho Google Analytics vào ứng dụng, bạn có thể bắt đầu ghi lại các sự kiện Play Games. Dưới đây là một số sự kiện mẫu mà bạn có thể ghi lại:
Sự kiện đăng nhập
Bundle bundle = new Bundle();
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, bundle);
Mở khoá thành tích
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ACHIEVEMENT_ID, achievementId);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.UNLOCK_ACHIEVEMENT, bundle);
Bạn cũng có thể truy cập vào bảng điều khiển Firebase từ Play Console bằng cách nhấp vào biểu tượng Firebase bên cạnh biểu tượng ứng dụng của bạn trong trang Chi tiết về trò chơi.
Khắc phục các lỗi thường gặp
Không xem được các sự kiện Play Games trong trang tổng quan Analytics
Xác minh rằng mã của bạn triển khai các sự kiện cho LOGIN, UNLOCK_ACHIEVEMENT hoặc POST_SCORE.
Xác minh rằng SDK đang ghi nhật ký các sự kiện bằng cách bật tính năng ghi nhật ký chi tiết.
Vì các thiết bị phân lô sự kiện để duy trì thời lượng pin, nên có thể mất một khoảng thời gian trước khi những sự kiện này xuất hiện trong trang tổng quan Analytics.
Không thể liên kết Google Play với Firebase
Bạn cần liên kết Google Play với Firebase bằng bảng điều khiển Firebase (settings > Cài đặt dự án > Các công cụ tích hợp > Google Play). Nếu bạn gặp vấn đề khi liên kết, hãy kiểm tra những điều sau:
Không truy cập được vào bảng điều khiển Firebase từ Bảng điều khiển Play
Đảm bảo rằng tài khoản nhà phát triển Google Play của bạn được liên kết với một ứng dụng Firebase. Trong PlayConsole (Bảng điều khiển), Chủ sở hữu hoặc Quản trị viên của tài khoản nhà phát triển Play có thể xem trạng thái liên kết trong phần settingsThiết lập > Dịch vụ được liên kết > Firebase.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-08 UTC."],[],[],null,["\u003cbr /\u003e\n\nFirebase can help level up your game:\n\n- Log Games events with Google Analytics, a free app measurement solution\n that provides insight on app usage and user engagement.\n\n- Use any of the [Firebase products that support games](/games), like\n Crashlytics, Remote Config, and more.\n\nGet started\n\n1. If you haven't already, create a Firebase project, and then add Firebase to\n your game ([C++](/docs/cpp/setup) \\| [Unity](/docs/unity/setup)).\n\n | Note the following:\n | - If you've previously linked your Google Play developer account to a Google Cloud project in the Play Console, use that same project for getting started with Firebase. Behind the scenes, a Firebase project is a Google Cloud project ([learn\n | more](/docs/projects/learn-more#firebase-cloud-relationship)).\n | - Make sure to enable Google Analytics during the Firebase project creation flow or enable it after project creation in the [*Integrations* tab](//console.firebase.google.com/project/_/settings/integrations/) of the Firebase console.\n2. [Link your Firebase app to your\n Google Play developer account](https://support.google.com/firebase/answer/6392038).\n This same link will be used by your Play Games services project.\n\n\n In the Firebase console, go to the\n [*Integrations* tab](https://console.firebase.google.com/project/_/settings/integrations).\n On the *Google Play* card, click **Link**, and then follow the on-screen\n instructions to create the link.\n\n3. Make sure that your app in Google Play is [set up to use\n Play Games services](https://developers.google.com/games/services/console/enabling).\n\n | When you're asked to specify whether your game already uses Google APIs, choose **Yes, my game already uses Google APIs**. Select your Firebase project from the list, and then click **Use**.\n\nLog Games events using Google Analytics\n\n1. [Add Google Analytics to your app.](/docs/analytics/get-started?platform=android)\n\n2. Once you've added the Firebase SDK for Google Analytics to your app,\n you can begin logging Play Games events. Here are some sample\n events you can log:\n\n - Login events\n\n Bundle bundle = new Bundle();\n mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, bundle);\n\n - Unlock achievements\n\n Bundle bundle = new Bundle();\n bundle.putString(FirebaseAnalytics.Param.ACHIEVEMENT_ID, achievementId);\n mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.UNLOCK_ACHIEVEMENT, bundle);\n\n - Scores on a leaderboard\n\n Bundle bundle = new Bundle();\n bundle.putLong(FirebaseAnalytics.Param.SCORE, score);\n bundle.putString(\"leaderboard_id\", leaderboardId);\n mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.POST_SCORE, bundle);\n\n3. You can view the logged events in the\n [Analytics dashboard](https://console.firebase.google.com/project/_/analytics/app/_/overview)\n of the Firebase console.\n\n You can also access the Firebase console from the\n [Play Console](//play.google.com/apps/publish/)\n by clicking the Firebase icon next to your app's icon in the Game details\n page.\n\nTroubleshooting common errors\n\nCannot view Play Games events in the Analytics dashboard\n\n- Check that you've [enabled Google Analytics for your Firebase\n project](https://support.google.com/firebase/answer/9289399#linkga)\n and that you've\n [integrated Google Analytics](/docs/analytics/get-started?platform=android)\n into your game.\n\n- Verify that your code implements events for `LOGIN`, `UNLOCK_ACHIEVEMENT`, or\n `POST_SCORE`.\n\n- Verify the SDK is logging events by enabling\n [verbose logging](/docs/analytics/events?platform=android#view_events_in_the_android_studio_debug_log).\n Because devices batch events to preserve battery life, it can take some time\n before these events are visible in the Analytics dashboard.\n\nCannot link Google Play to Firebase\n\nYou need to [link Google Play to Firebase](https://support.google.com/firebase/answer/6392038)\nusing the Firebase console\n(settings \\\u003e *Project settings* \\\u003e\n*Integrations* \\\u003e *Google Play*). If you're having trouble linking, check the\nfollowing:\n\n- Make sure that your app meets all the\n [prerequisites](https://support.google.com/firebase/answer/6392038#prerequisites)\n for linking.\n\n- Make sure that you have the\n [required access](https://support.google.com/firebase/answer/6392038#permissions-and-roles)\n for creating the link.\n\nCannot access the Firebase console from the Play Console\n\nMake sure that your Google Play developer account is linked to a Firebase app. In the\n[Play Console](https://play.google.com/apps/publish/), an Owner or\nAdmin of the Play developer account can view the linking status under\nsettings*Setup* \\\u003e *Linked Services* \\\u003e *Firebase*."]]