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.
Trang này mô tả cách triển khai các tính năng liên quan đến cách người dùng đăng nhập hoặc đăng xuất bằng Google One Tap.
Tự động đăng nhập người dùng
Google One Tap hỗ trợ tính năng tự động đăng nhập, mang đến trải nghiệm người dùng (UX) mượt mà bằng cách loại bỏ các bước thủ công mà người dùng phải thực hiện khi quay lại trang web của bạn. Người dùng không cần nhớ Tài khoản Google mà họ đã chọn trong lần truy cập gần đây nhất, nhờ đó giảm khả năng tạo các tài khoản trùng lặp không cần thiết trên nền tảng của bạn.
Tính năng tự động đăng nhập nhằm bổ sung cho nút Đăng nhập bằng Google và hộp thoại Một lần chạm. Phương thức này được thiết kế để sử dụng trên toàn bộ trang web của bạn, trong đó việc đăng ký hoặc chuyển đổi tài khoản theo cách thủ công chỉ xảy ra sau khi người dùng đăng xuất khỏi trang web của bạn lần đầu tiên.
Để tính năng Tự động đăng nhập diễn ra, bạn phải đáp ứng các điều kiện sau:
trước tiên, người dùng phải đăng nhập vào Tài khoản Google của họ và
đã đồng ý chia sẻ hồ sơ tài khoản của họ với ứng dụng của bạn trước đó và
khi sử dụng FedCM, chỉ thực hiện một lần đăng nhập trong 10 phút qua.
Tính năng Một lần nhấn sẽ xuất hiện khi có nhiều lần đăng nhập xảy ra trong khoảng thời gian này.
khi sử dụng FedCM, Chrome yêu cầu người dùng xác nhận lại rằng họ muốn đăng nhập vào trang web bằng Tài khoản Google trong mỗi phiên bản Chrome, ngay cả khi người dùng đã phê duyệt trang web trước khi triển khai FedCM. Thay đổi này có thể ảnh hưởng đến tỷ lệ chuyển đổi trên trang web hiện tại của bạn khi sử dụng tính năng Thanh toán không tiếp xúc. Trong bản cập nhật Chrome M121, tính năng Cải thiện tính năng Tự động đăng nhập giúp giảm thiểu vấn đề tỷ lệ chuyển đổi giảm.
Đối với các trang đã bật tính năng Tự động đăng nhập và nếu đáp ứng các điều kiện này, thông tin xác thực mã thông báo nhận dạng của người dùng sẽ tự động được trả về mà không cần người dùng tương tác. Nếu không đáp ứng các điều kiện này và ngay cả khi bạn bật tính năng Tự động đăng nhập trên trang, người dùng sẽ mặc định sử dụng quy trình Một lần nhấn để đăng nhập hoặc đồng ý. Nếu có nhiều Tài khoản Google và truy cập vào trang web của bạn, trước tiên, người dùng phải đăng nhập vào một Tài khoản Google và đồng ý với tài khoản đó.
Bạn có thể đo lường tỷ lệ thành công của tính năng Tự động đăng nhập bằng cách sử dụng giá trị auto trong trường select_by của đối tượng thông tin xác thực được trả về.
Để bật tính năng tự động đăng nhập, hãy thêm data-auto_select="true" vào mã của bạn, như minh hoạ trong đoạn mã sau:
Khi người dùng đăng xuất khỏi trang web của bạn, họ có thể được chuyển hướng đến một trang mà lời nhắc Google One Tap sẽ tự động hiển thị. Đối với chế độ thiết lập này, bạn phải cấm tính năng tự động chọn. Nếu không, người dùng sẽ tự động đăng nhập lại, dẫn đến trải nghiệm người dùng bị lặp lại.
Sử dụng FedCM
Để cải thiện trải nghiệm người dùng, có một khoảng thời gian yên tĩnh 10 phút giữa mỗi lần đăng nhập tự động. Trong khoảng thời gian này, lời nhắc Nhấn một lần sẽ xuất hiện. Người dùng cần phải nhấp rõ ràng vào tính năng Một lần chạm để đăng nhập.
Không có FedCM
Để cấm tính năng tự động chọn sau khi người dùng đăng xuất, hãy thêm tên lớp g_id_signout vào tất cả các đường liên kết và nút đăng xuất. Hãy xem đoạn mã sau:
<div class="g_id_signout">Sign Out</div>
Bạn cũng có thể sử dụng đoạn mã JavaScript sau để đăng xuất:
Để ngăn trải nghiệm người dùng bị lặp lại, trạng thái đã đăng xuất của người dùng được lưu trữ trong một cookie có tên g_state do thư viện Dịch vụ nhận dạng của Google đặt. Theo mặc định, miền cookie được đặt thành miền của trang hiện tại. Nếu tính năng Một lần nhấn hiển thị trên miền gốc và miền con, thì cookie trạng thái phải hiển thị trên tất cả miền của bạn. Sử dụng thuộc tính data-state_cookie_domain để đặt miền cookie g_state thành miền mẹ. Ví dụ: thêm data-state_cookie_domain="example.com" vào phần tử g_id_onload cho miền gốc example.com và miền con có tên webapp.example.com.
Nếu có một dịch vụ theo dõi tất cả cookie được sử dụng trong miền của bạn, bạn cần thông báo cho họ về cookie g_state.
Nếu bạn không muốn tải thư viện ứng dụng trên các trang sau khi đăng nhập, hãy sử dụng các giải pháp sau để ngăn trải nghiệm người dùng bị lặp lại sau khi đăng xuất:
Khi đăng xuất, hãy chuyển hướng người dùng đến một trang (ví dụ: https://example.com/logged_out) không hiển thị tính năng Một lần chạm hoặc luôn tắt tính năng đăng nhập tự động.
Khi đăng xuất, hãy thêm một tham số vào URL. Ví dụ: logged_out=1.
Khi hiển thị tính năng Một lần chạm bằng API JavaScript, hãy kiểm tra tham số URL đó và tắt tính năng tự động đăng nhập nếu có.
Hành trình chính của người dùng
Trang tự động đăng nhập.
Sử dụng FedCM
Người dùng có thể đóng lời nhắc Một lần nhấn bằng cách nhấp vào nút X. Để cân nhắc đến khả năng hỗ trợ tiếp cận, mã thông báo nhận dạng sẽ được chia sẻ với trang web của bạn ngay cả khi người dùng nhấp vào nút X.
Để cải thiện trải nghiệm người dùng, có một khoảng thời gian yên tĩnh 10 phút giữa mỗi lần đăng nhập tự động. Trong khoảng thời gian này, lời nhắc Nhấn một lần sẽ xuất hiện. Người dùng cần phải nhấp rõ ràng vào tính năng Một lần chạm để đăng nhập.
Không có FedCM
Nếu người dùng không nhấp vào nút Huỷ trong vòng 5 giây, thì một mã thông báo nhận dạng sẽ được chia sẻ với trang web của bạn.
Khi bạn huỷ quy trình Đăng nhập, dựa trên số phiên Google đang hoạt động, trang chọn tài khoản hoặc trang người dùng cũ sẽ xuất hiện.
[[["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-05-23 UTC."],[[["\u003cp\u003eGoogle One Tap enables automatic sign-in, providing a frictionless user experience by eliminating manual login steps for returning users.\u003c/p\u003e\n"],["\u003cp\u003eAutomatic sign-in works when users are signed in to their Google Account, have previously granted consent, and (for FedCM) haven't attempted sign-in within the last 10 minutes.\u003c/p\u003e\n"],["\u003cp\u003eTo enable automatic sign-in, add \u003ccode\u003edata-auto_select="true"\u003c/code\u003e to your One Tap implementation code.\u003c/p\u003e\n"],["\u003cp\u003eWhen implementing sign-out functionality, ensure auto-selection is disabled to prevent a login loop, which can be achieved by using the \u003ccode\u003eg_id_signout\u003c/code\u003e class or \u003ccode\u003egoogle.accounts.id.disableAutoSelect()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eOne Tap sign-out (disabling automatic sign-in) is temporary and does not sign users out of your website or Google services.\u003c/p\u003e\n"]]],[],null,["This page describes how to implement features related to how users sign in or\nsign out with Google One Tap.\n\nSign in users automatically\n\nGoogle One Tap supports automatic sign-in, which provides a frictionless user\nexperience (UX) by removing the manual steps users must take when returning\nto your site. Users don't need to remember which Google Account they selected\nduring their last visit, decreasing the chances of unnecessary duplicate\naccounts being created on your platform.\n\nAutomatic sign-in is intended to complement our Sign in with Google button\nand One Tap dialogs. It is designed to be used across your entire site, with\nmanual sign-up or switching accounts occurring only after the user has first\nsigned-out of your site.\n\nFor Automatic sign-in to occur the following conditions are required:\n\n- users must first be signed-in to their Google Account, and\n- previously granted consent to share their account profile with your app, and\n- when using FedCM, made only a single sign-in attempt in the last 10 minutes. One Tap is displayed when repeated sign-in attempts occur during this window.\n- when using FedCM, Chrome requires users to reconfirm that they want to sign in to the website with Google Account in each Chrome instance even if the user approved the website prior to the FedCM rollout. This change may affect conversion rate on your existing site using One Tap. In Chrome M121 update, [Auto Sign-in improvement](/identity/gsi/web/reference/release-notes#2023-12-21) mitigates conversion rate drop issue.\n\nFor pages where Automatic sign-in is enabled and if these conditions are met\nthe user's ID token credential is automatically returned without any user\ninteraction. If these conditions are not met, and even if Automatic sign-in is\nenabled on the page, the user defaults to the One Tap flow for sign-in or\nconsent. If a user has multiple Google Accounts and visits your site they are\nrequired to first sign-in to a single Google Account and to have provided\nconsent for that account.\n\nYou may measure Automatic sign-in success rate using the `auto` value in the\n[select_by](/identity/gsi/web/reference/js-reference#select_by) field of the returned credential object.\n\nTo enable automatic sign-in, add `data-auto_select=\"true\"` to your code, as\nshown in the following snippet: \n\n \u003cdiv id=\"g_id_onload\"\n data-client_id=\"\u003cvar translate=\"no\"\u003eYOUR_GOOGLE_CLIENT_ID\u003c/var\u003e\"\n data-login_uri=\"\u003cvar translate=\"no\"\u003ehttps://your.domain/your_login_endpoint\u003c/var\u003e\"\n data-auto_select=\"true\"\u003e\n \u003c/div\u003e\n\n| **Note:** The [upgraded One Tap UX for ITP browsers](/identity/gsi/web/guides/features#upgraded_ux_on_itp_browsers) doesn't support auto sign-in.\n\nSign out\n\nWhen a user signs out of your website, they can be directed to a page where a\nGoogle One Tap prompt is automatically displayed. For this setup, auto-selection\nmust be prohibited. Otherwise, the user is automatically signed in again, which\nleads to a dead-loop UX. \n\nUsing FedCM\n\nTo improve user experience, there is a 10 minute quiet period between every\nautomatic sign-in attempt. During this time period, One Tap prompt is\ndisplayed instead. Users need to explicitly click One Tap to sign in.\n\nWithout FedCM\n\nTo prohibit auto-selection after a user signs out, add the class name\n`g_id_signout` to all of your logout links and buttons. See the following code\nsnippet: \n\n \u003cdiv class=\"g_id_signout\"\u003eSign Out\u003c/div\u003e\n\nThe following JavaScript code snippet can also be used for sign out: \n\n const button = document.getElementById('signout_button');\n button.onclick = () =\u003e {\n google.accounts.id.disableAutoSelect();\n }\n\nTo prevent a dead-loop UX, user signed-out status is stored in a cookie named\n`g_state` that is set by the Google Identity Services library. By default the\ncookie domain is set to the domain of current page. If One Tap is displayed\non the parent domain and subdomains, the state cookie must be visible across\nall of your domains. Use the `data-state_cookie_domain` attribute to set the\n`g_state` cookie domain to your parent domain. For example, add\n`data-state_cookie_domain=\"example.com\"` to the `g_id_onload` element for a\nparent domain of `example.com` and a subdomain named `webapp.example.com`.\n| **Key Point:** If One Tap is displayed on multiple domains, you need to set the `g_state` cookie domain to your parent domain.\n\nIf you have a service that monitors all of the cookies used in your domain,\nyou need to notify them of the `g_state` cookie.\n| **Key Point:** Feel free to use other ways to prevent the dead-loop UX on log out moment.\n\nIf you don't want to load the client library on your post-login pages, use\nthese solutions to prevent a dead-loop UX after log out occurs:\n\n- On log out, redirect users to a page (say, `https://example.com/logged_out`) where One Tap is not displayed, or where auto sign-in is always disabled.\n- On log out, add a parameter to the URL. For example, `logged_out=1`. When rendering One Tap by JavaScript API, check that URL parameter and disable auto sign-in when present.\n\n| **Warning:** The term 'sign out' here refers to temporarily disabling One Tap Automatic sign-in for one day. This API does not sign out your users out of your website or any Google websites.\n\nKey user journeys\n\nThe automatic sign-in page. \n\nUsing FedCM\n\nUsers can close the One Tap prompt by clicking the **X** button. For\naccessibility consideration, an ID token is shared with your website\neven if users click the **X** button.\n\nTo improve user experience, there is a 10 minute quiet period between every\nautomatic sign-in attempt. During this time period, One Tap prompt is\ndisplayed instead. Users need to explicitly click One Tap to sign in.\n\nWithout FedCM\n\nIf users don't click the **Cancel** button within 5 seconds, an ID token\nis shared with your website.\n\nWhen Sign-In is cancelled, based on the number of active Google sessions,\neither the account chooser page or the returning user page displays.\n\n- Multiple Google sessions\n\n- Single Google Sessions\n\n| **Key Point:** Once cancelled, Automatic sign-in is disabled for one day."]]