-
Notifications
You must be signed in to change notification settings - Fork 13
Conditionally make requests to Google services based on client country detected by IP geolocation #548
Conversation
That's because of the timeout that appears in the console. If it takes longer that 10s to do the IP geolocation, it just assumes a default location. |
3f62733
to
2158d9f
Compare
Taking another look at this. |
Hmm actually, can't review this because of merge conflicts. Will wait until they are resolved before checking this out. |
2158d9f
to
84eb579
Compare
I fixed the merge conflict but you will need an API key to merge this properly. I'll update the testing instruction and let everyone know when this is ready. |
@open-apparel-registry/operations I originally began the implementation of detecting the brower's country using the free http://userinfo.io/ service. There was some significant downtime of that service last Thursday that prompted me to find a paid alternative. I evaluated https://ipinfo.io/, https://ipdata.co/, and https://ipgeolocation.io This PR has now has a successful integration of the https://ipgeolocation.io service. I chose https://ipgeolocation.io for the following reasons:
I tested this PR with a free personal account but would like to sign up for a paid account under a company address and credit card to complete the implementation. Next Steps:
|
I think this looks good. The support for using request origin sounds elegant. 👍 It's worth surfacing that MaxMind seems to be an informal standard for GeoIP. For example, BIND defaults to MaxMind: https://kb.isc.org/docs/aa-01149. I also believe their GeoIP file format is baked into a couple programming languages, including PHP. I did a brief search, and it looks like MaxMind also charges $15 per 150,000 requests ( See: https://www.maxmind.com/en/geoip2-precision-country-service
I can wire this up and ping you on Slack. |
42f656b
to
d6d7c7f
Compare
This is now ready for another look. I updated the description with new demo screenshots and revised instructions. Thanks, Rocky, for jumping on this and setting up an ipgeolocation.io account. |
Tested with the mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 tested, works nicely. Took a while to get the credentials in Last Pass, but this works well overall. Glad we're able to support these users.
Thanks for taking the time to exercise this. |
The free userinfo.io service had some significant downtime during our testing, prompting us to select a more reliable alternative. We evaluated ipinfo.io, ipdata.co, and ipgeolocation.io and chose ipgeolocation.io for the following reasons: - Low cost: Their $15 monthly plan covers 150,000 requests. 2 orders of magnitude more than our current page view count. Additional blocks of 50,000 requests are $5. - A dashboard with impressive uptime statistics. - Support for using request origin rather than an API key, allowing us to make requests from the client without worrying about exposing a key or taking on the burden of writing our own server-side proxy. We are allowed one origin on the lowest subscription tier, but that includes subdomains so it will cover both staging and production. This commit includes support for conditionally using an API key in development, but we don't really need IP geolocation so it will be optional in development.
With this change the application now waits until a request for client information has succeeded or failed before loading the Google map and uses the fetched country code to set the region for the the Google map.
Loading Google translate library in China requires that we request the script from google.cn rather than google.com. To allow this conditional loading we moved the script tag from `index.html` into a new component that uses a lifecycle method to append the script tag with the proper `src`.
Conditionally sets the host for the static image request based on whether or not the client is in China and passes the detected country code to the `region` parameter.
We do not want non-responsive requests to the client info API to block Google related features from loading.
d6d7c7f
to
1f2e113
Compare
Overview
Modifies the code that makes requests to Google services to pass the detected country code as an argument when appropriate and to switch to China-based hosts when required.
Connects #537
Connects #539
Demo
US
IP Geolocation
Translation
Static Map
Dynamic Map
CN
IP Geolocation
Translation
Static Map
Dynamic Map
Testing Instructions
The screencast in the Demo section shows the app working both on a US network and connected to a China-hosted VPN endpoint.
The IP location screenshots were taken while this branch was deployed to staging, showing the ipgeolocation.io service working correctly.
clientInfo.js
..cn
domains.to
.env.backend
and rerunning./scripts/server
Checklist
fixup!
commits have been squashed