Warning: This data is provided under the Google User Data Policy. Please review and comply with the policy. Failure to do so might result in project or account suspension.

Use the One Tap JavaScript API

If preferred, you can use only JavaScript code to trigger the One Tap prompt.

To configure the One Tap prompt in JavaScript, you first need to call the initialize() method. Then, call the prompt() method to display the prompt UI. See the following code snippet:

<script>
  window.onload = function () {
    google.accounts.id.initialize({
      client_id: 'YOUR_GOOGLE_CLIENT_ID',
      callback: handleCredentialResponse
    });
    google.accounts.id.prompt();
  }
</script>

To receive prompt UI status notifications, provide a callback function to the prompt() method. See the following code snippet:

<script>
  window.onload = function () {
    google.accounts.id.initialize({
      client_id: 'YOUR_GOOGLE_CLIENT_ID',
      callback: handleCredentialResponse
    });
    google.accounts.id.prompt((notification) => {
        if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
            // try next provider if OneTap is not displayed or skipped
        }
    });
  }
</script>