react-native-google-places icon indicating copy to clipboard operation
react-native-google-places copied to clipboard

[Feature] Support session tokens

Open rodperottoni opened this issue 4 years ago • 10 comments

One of the apps I currently maintain has been severely affected by the Places API price changes introduced this year. Overnight my client saw his Google Places bill increase by ~10x, and upon investigating a bit further I came to the conclusion that the lack of support for session tokens on this module was the cause for this price increase. I do not use the provided Autocomplete Modal, so I'm not the right person to tell whether it correctly uses session tokens or not. This pull request only addresses the scenario where an app is making multiple getAutocompletePredictions calls, optionally followed by a lookUpPlaceByID call.

This pull request fixes this issue by exposing a new function named beginAutocompleteSession that generates a new Session Token on the module's class instance. Further calls to getAutocompletePredictions and lookUpPlaceByID will then use this Session Token. There's also a new function cancelAutocompleteSession that does the opposite - cleans up any session tokens being kept on the module's class instance.

I'm keen to discuss better ways to implement this as well.

Read more: Places API - Session Tokens SKU: Autocomplete (included with Places Details) – Per Session

rodperottoni avatar Oct 22 '19 04:10 rodperottoni

Is there any news on this?

0x2539 avatar Nov 21 '19 03:11 0x2539

I can finally see the prices going down again after publishing my app with the changes in this pull request. We went through 5 months of turmoil with expenses exceeding 4k USD a month and I'm sure more people will go through the same if they don't become aware of how important session tokens are. Additionally, here's a tip if you're after this feature but cant wait for this pull request to be approved. You can add a specific pull request as a dependency of your project: "react-native-google-places": "tolu360/react-native-google-places#262/head"

rodperottoni avatar Nov 28 '19 05:11 rodperottoni

Notice the huge drop after properly using session tokens.

Screen Shot 2019-11-28 at 3 30 01 pm

Screen Shot 2019-11-28 at 3 26 58 pm

rodperottoni avatar Nov 28 '19 05:11 rodperottoni

Hi @rodperottoni, this looks well put together I must say. I am sorry I have been away and just looking at this. I am working on releasing a v4, a week from now, at the latest. Thank you for your contributions.

tolu360 avatar Jun 15 '20 14:06 tolu360

@rodperottoni I don't think it is working. I tried from your fork.

AkshayAdiga1997 avatar Jun 18 '20 17:06 AkshayAdiga1997

@rodperottoni I don't think it is working. I tried from your fork.

Hey Akshay. The images above show the exact opposite. After I started using session tokens our monthly bill went down significantly.

rodperottoni avatar Jun 20 '20 04:06 rodperottoni

@rodperottoni I don't think it is working. I tried from your fork.

Hey Akshay. The images above show the exact opposite. After I started using session tokens our monthly bill went down significantly.

The number of requests in the maps console is the same as the number of keystrokes that I make in the search bar (when the sessiontoken is set even after executing RNGooglePlaces.beginAutocompleteSession();)

AkshayAdiga1997 avatar Jun 20 '20 05:06 AkshayAdiga1997

The number of requests in the maps console is the same as the number of keystrokes that I make in the search bar (when the sessiontoken is set) even after executing RNGooglePlaces.beginAutocompleteSession();

I think you're not understanding what an autocompleteSession is. An autocompleteSession groups multiple Places API calls into a single Product SKU, for example: an Autocomplete + Details API call session.

In other words, a session token tells Google that calls using the same token should be grouped and charged as ONE PRODUCT.

With that said, It's up to you to throttle or debounce your calls to getAutocompletePredictions. Please take your time and read their billing page to avoid huge charges like the ones I posted above.

rodperottoni avatar Jun 20 '20 05:06 rodperottoni

Hello,

Thanks for the contributions and the great library. Is there any update for v4 or merging this with the master branch?

thehexatown avatar Sep 13 '20 19:09 thehexatown

@tolu360 We really need this PR work. Can you please let us know what can be the ETA of merging this?

passionInfinite avatar Feb 08 '21 20:02 passionInfinite