REMINDER

Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

Retrieve visitor country code?



  • Is it possible to get the visitors country from the back-end?

    I know it's available from CloudFront-Viewer-Country and can be passed to the Lambda.



  • You could try looking in the headers. If not, the best thing to do would probably do a Geo IP lookup, you can indeed get the IP from the backend. I don't think browser headers send country code, they barely send timezone info 😉

    I think I have code for extracting the IP address if you need it, but if you print all the headers from the request you should see how to access it.

    Cheers @ThomasD



  • @Daniel-Mulroy

    Yeah, I can use a GeoIP lookup service since the IP is in the headers.

    Just thought I'd avoid the extra cost since it's already available in AWS.



  • In case you haven't found this out yourself yet, you can access it from within a CloudBackend function using:

    event["HEADERS"]["CloudFront-Viewer-Country"]
    

    Hope this helps!



  • @Daniel-Mulroy

    Glad you wrote that!

    I looked for it using the "Try" feature, but that doesn't return the CloudFront headers. I would have missed it for sure.

    Problem is, this will eat up the back-end quota instantly because every visitor would need to execute it...



  • Can you help me understand the use-case a bit more? Maybe I'll get a flash of inspiration if I know more about what you're trying to do 🙂


Log in to reply