Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support session tokens #262

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

rodperottoni
Copy link

@rodperottoni rodperottoni commented Oct 22, 2019

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

@0x2539
Copy link

0x2539 commented Nov 21, 2019

Is there any news on this?

@rodperottoni
Copy link
Author

rodperottoni commented Nov 28, 2019

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": "#262/head"

@rodperottoni
Copy link
Author

rodperottoni commented Nov 28, 2019

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

@tolu360
Copy link
Owner

tolu360 commented Jun 15, 2020

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.

@AkshayAdiga1997
Copy link

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

@rodperottoni
Copy link
Author

@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.

@AkshayAdiga1997
Copy link

AkshayAdiga1997 commented Jun 20, 2020

@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();)

@rodperottoni
Copy link
Author

rodperottoni commented Jun 20, 2020

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.

@thehexatown
Copy link

Hello,

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

@passionInfinite
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants