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.
Google Analytics có một lệnh gọi setUserID, cho phép bạn lưu trữ mã nhận dạng người dùng cho cá nhân sử dụng ứng dụng của bạn. Lệnh gọi này là không bắt buộc và thường được các tổ chức muốn sử dụng Analytics kết hợp với BigQuery để liên kết dữ liệu phân tích cho cùng một người dùng trên nhiều ứng dụng, nhiều thiết bị hoặc nhiều nhà cung cấp dịch vụ phân tích sử dụng.
Có nhiều cách để tạo mã nhận dạng người dùng hợp lệ. Một cách là sử dụng giá trị nhận dạng mà bạn chỉ định và chỉ bạn mới có thể theo dõi lại một người dùng riêng lẻ. Để xem xét một ví dụ có thể xảy ra, hãy xem xét một nhà phát triển trò chơi di động giả định, AwesomeGameCompany, có AwesomeGameCompanyID nội bộ riêng mà họ tạo cho mọi người dùng. Nếu tổ chức bên ngoài không thể theo dõi AwesomeGameCompanyID đó trở lại người dùng ban đầu, thì họ có thể cân nhắc sử dụng AwesomeGameCompanyID đó (hoặc tốt hơn là phiên bản băm của AwesomeGameCompanyID) làm giá trị mã nhận dạng người dùng cho Analytics.
Sau đó, họ có thể tính toán các giá trị như tổng số tiền mà người dùng đã chi tiêu trên tất cả các trò chơi của họ.
Bạn không bao giờ cần đặt mã nhận dạng người dùng để Analytics hoạt động đúng cách.
Nếu chỉ muốn tìm các sự kiện thuộc cùng một người dùng cho cùng một ứng dụng trên một thiết bị, bạn có thể sử dụng user_pseudo_id.
Giá trị này được Analytics tự động tạo và được lưu trữ trong BigQuery cho mỗi sự kiện.
Đặt mã nhận dạng người dùng
Bạn có thể đặt mã nhận dạng người dùng bằng phương thức sau:
Swift
Lưu ý: Sản phẩm Firebase này không có trên mục tiêu macOS.
Analytics.setUserID("123456")
Objective-C
Lưu ý: Sản phẩm Firebase này không có trên mục tiêu macOS.
Sau khi đặt mã nhận dạng người dùng, tất cả các sự kiện trong tương lai sẽ tự động được gắn thẻ bằng giá trị này và bạn có thể truy cập vào giá trị đó bằng cách truy vấn user_id trong BigQuery. Việc thêm mã nhận dạng người dùng sẽ không ảnh hưởng đến bất kỳ sự kiện nào mà Google Analytics đã ghi lại trước đó.
Để tìm hiểu thêm về cách truy cập vào dữ liệu Analytics trong BigQuery, vui lòng xem hướng dẫn phát triển này.
[[["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-08-30 UTC."],[],[],null,["Google Analytics has a `setUserID` call, which allows you to\nstore a user ID for the individual using your app. This call is optional, and\nis generally used by organizations that want to use Analytics\nin conjunction with BigQuery to associate analytics data for the same user across\nmultiple apps, multiple devices, or multiple analytics providers.\n| **Note:** You are responsible for ensuring that your use of the user ID is in accordance with the [Google Analytics Terms of Service](https://www.google.com/analytics/terms/). This includes avoiding the use of impermissible personally identifiable information, and providing appropriate notice of your use of identifiers in your Privacy Policy. Your user ID must not contain information that a third party could use to determine the identity of an individual user. For example, you cannot use a user's email address or social security number as a user ID.\n\nThere are many ways you can construct valid user IDs. One approach is to use an\nidentifier you assign and only you can track back to an individual user. For one\npossible example, consider a hypothetical mobile game developer,\nAwesomeGameCompany, that has their own internal `AwesomeGameCompanyID` that they\ncreate for every user. If it isn't possible for an outside organization to track\nthat `AwesomeGameCompanyID` back to the original user, they might consider using\nthat `AwesomeGameCompanyID` --- or, better yet, a hashed version of\n`AwesomeGameCompanyID` --- as the user ID value for Analytics.\nThis would then allow them to calculate values such as a user's total spend\nacross all of their games.\n\nSetting a user ID is never required for Analytics to work correctly.\nIf you're only interested in finding events belonging to the same user for the\nsame app on a single device, you can use the `user_pseudo_id`.\nThis value is generated automatically by Analytics and is\nstored within BigQuery for each event.\n\nSetting the user ID\n\nYou can set a user ID with the following method: \n\nSwift\n\n\n**Note:** This Firebase product is not available on the macOS target. \n\n```swift\nAnalytics.setUserID(\"123456\")\n```\n\nObjective-C\n\n\n**Note:** This Firebase product is not available on the macOS target. \n\n```objective-c\n[FIRAnalytics setUserID:@\"123456\"]\n```\n\nAndroid \n\n```java\nmFirebaseAnalytics.setUserId(\"123456\");\n```\n\nWeb \n\n```java\nimport { getAnalytics, setUserId } from \"firebase/analytics\";\n\nconst analytics = getAnalytics();\nsetUserId(analytics, \"123456\");\n```\n\nWeb \n\n```java\nfirebase.analytics().setUserId(\"123456\");\n```\n\nDart \n\n```dart\nawait FirebaseAnalytics.instance.setUserId(id: '123456');\n```\n\nUnity \n\n```c#\nFirebase.Analytics.FirebaseAnalytics.SetUserID(\"123456\");\n```\n\nC++ \n\n```c++\nanalytics::SetUserId(\"123456\");\n```\n\nAfter setting a user ID, all future events will be automatically tagged\nwith this value, and you can access it by querying for the `user_id`\nvalue in BigQuery. Adding a user ID will not affect any\nevents previously recorded by Google Analytics.\n\nTo find out more about accessing Analytics data in BigQuery, please see\nthis [development guide](https://cloud.google.com/solutions/mobile/mobile-firebase-analytics-big-query)."]]