20

I have a website that uses address autocomplete on multiple pages--address book, shipping address, billing address. With the billing changes releasing next month, we can convert the Autocomplete process to use sessions instead of individual keystrokes. (https://cloud.google.com/maps-platform/user-guide/pricing-changes/#billing-changes)

  • How long is an AutocompleteSessionToken good for? The current page? An hour? Twelve? Permanently, with it counting against the limit each time it shows up in a new month?
  • If a session token does expire, and we send that token with a request, what's the result going to be? If the customer leaves a webpage open for a day and comes back to pick up, and our session data hasn't expired, how do we make sure they don't get autocomplete errors?
xomena
  • 31,125
  • 6
  • 88
  • 117
jbhelfrich
  • 410
  • 1
  • 3
  • 9

2 Answers2

16

As far as I can see there is no official documentation regarding session duration for Places API in Google Maps Platform. I can share some information about sessions obtained from the technical support, however, it doesn't provide exact value for session duration and it looks like Google won't reveal the exact value.

First of all, if you use the built-in Autocomplete widget of Maps JavaScript API, it generates sessions for you automatically, so no need to worry about it.

If you create your own widget, you should be aware that sessions do not last very long. An autocomplete session includes some Autocomplete requests (to retrieve suggestions on a place as the user types), and at most one Places Details request (to retrieve details about the place selected by the user).

The same session token is passed to the Autocomplete and the subsequent Place Detail request.

A session starts with the first Autocomplete request (which typically happens when the user starts typing). Typically, a Places Details call is made after the user has selected one of the Autocomplete suggestions.

After a user has selected a place (for example, a Places Details call is made), a new session must be started, with a new session token.

A session token cannot be used for more than one user session. If a token is reused, the session will be considered invalid and the requests will be charged as if no session token was provided.

If session token is expired or invalidated you will be charged on the per keystroke basis. So each autocomplete request will be charged.

I hope you find this information useful.

xomena
  • 31,125
  • 6
  • 88
  • 117
  • Can you expand on this `f you use the built-in Autocomplete widget of Maps JavaScript API, it generates sessions for you automatically,` what clasifies as the built in one? As in put a dynamic map on the page that has a search box in the map? – James Jun 04 '18 at 17:37
  • 2
    Built-in widgets are `google.maps.places.Autocomplete` and `google.maps.places.SearchBox`. They will generate session tokens for you automatically. If you use `google.maps.places.AutocompleteService`, you should create session tokens yourself. Have a look at example of session token in https://cloud.google.com/maps-platform/user-guide/pricing-changes/ – xomena Jun 04 '18 at 17:50
  • @xomena I see the Google API widgets are not generating same tokens per session, instead, a different token is generated for every request. Please help. https://stackoverflow.com/questions/51728344/google-places-autocomplete-widget-is-generating-a-new-session-key-per-every-requ – Mahesh Bongani Aug 23 '18 at 14:45
  • @xomena I am using the sessiontoken in my autocomplete and details request but I get charged for the Autocomplete without Place Details SKU. Any ideas? – Michael Nov 19 '18 at 17:52
  • @Michael Do you execute place details request after autocomplete? Do you pass the same session token to place details? Do you change session token once you requested a detailed information? – xomena Nov 19 '18 at 18:06
  • @xomena yes, yes and yes. I execute a couple or more autocomplete requests with token ASD and then when the user selects a place I do a details request with token ASD. After that a new session token is generated. The parameter name I am using is `sessiontoken` for both and `place_id` for the details request. Also, I don't see any feedback in the API response about the session token. – Michael Nov 19 '18 at 18:09
  • @Michael In this case try to contact technical support team via https://console.cloud.google.com/google/maps-apis/support. They should be able to figure out what is happening based on their internal logs. – xomena Nov 19 '18 at 21:37
  • What if user cancel the session (user not tap the suggestion) and try different keyword ? should create new token for new keyword ? – Ardy Febriansyah Mar 14 '21 at 16:54
  • How on earth are you supposed to know when to create a new session token if the user didn't choose a prediction!? I assumed you'd have to create a ttl and change it once this is passed but if they don't disclose this information then how can it work? – Richard Scarrott Oct 12 '21 at 14:24
  • @riscarrott, My thoughts exactly. This is simply a bad API. A user could start looking something up, get distracted, come back five minutes later and make a selection. If you don't refresh your token after a timeout period, every keystroke following the distraction would get charged. A better API would be to end a session when a place details lookup occurs (enforced by allowing the token to be part of the details lookup payload). – devuxer Mar 15 '22 at 20:13
15

As a customer of Google Maps, when we contacted their support team, an agent that worked with us told us that the timeout is 3 minutes.

Joe Chung
  • 171
  • 2
  • 4
  • I just wanted to add that the official documentation states `within a few minutes of the beginning of the session`, so the 3 minutes you were quoted may change over time https://developers.google.com/places/android-sdk/usage-and-billing#ac-no-details-session – TheIT Jul 10 '19 at 00:48