Handle guest users

To provide the best user experience, you might want to save state across multiple conversations with a user or access user data in one of the following ways:

  • userStorage is an opaque token that you can persist across multiple conversational sessions with a particular user.
  • Account Linking with the sign-in helper lets you link the user's Google account with your own account management backend. This gives you the most control in storing user information and preferences.

However, these features won't work unless Google can verify the user.

  • For user storage, storing data or retrieving data doesn't work if the status is GUEST.
  • For account linking, the sign-in helper won't work if the user verification status is GUEST.

This page explains how to determine whether a user is verified or a guest, and how to handle the conversation for guest users.

How we determine user verification status

At the start of each conversation, we set the user's verification status based on a variety of indicators when the conversation starts, such as:

  • The user has personal results turned off.
  • The user disabled their Web & App Activity. Keep in mind that some users may have this setting disabled at the domain level.
  • If a device has Voice Match enabled, and the match fails or the user invokes the Assistant without using their voice (such as a long press on a Google Home).
  • The user isn't signed in.

Handle user verification status

The user verification status returns a value of GUEST or VERIFIED. You should always check this status before storing data with user storage or starting an account linking flow, to prevent guest users from interacting with a feature that will fail for them.

The following code checks the user's verification status before asking them about storing their location, and pivots the conversation if they're a GUEST:

Node.js

app.intent('Remember Location', (conv) => {
  const zipCode = conv.device.location.zipCode;
  if (conv.user.verification === 'VERIFIED') {
    // This user is verified
    conv.ask('Should I remember ' + zipCode + ' for next time?');
  } else {
    // This user is a guest
    conv.ask('I can\'t save your location right now, ' +
      'but you can tell me again next time! What else can I help with?');
  }
});

Java

@ForIntent("Remember Location")
public ActionResponse rememberLocation(ActionRequest request) {
    User user = request.getUser();
    String zipCode = request.getDevice().getLocation().getZipCode();
    String verificationStatus = user.getUserVerificationStatus();
    ResponseBuilder responseBuilder = getResponseBuilder(request);
    if (verificationStatus.equals("VERIFIED")) {
        // This user is verified
        responseBuilder.add("Should I remember " + zipCode + " for next time?");
    } else {
        // This user is a guest
        responseBuilder.add("I can’t save your location right now, but " +
            "you can tell me again next time! What else can I help with?");
    }
    return responseBuilder.build();
}