Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    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?

    Cloud Backend (Cloud DB, API Builder)
    3
    9
    528
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Thomas D last edited by Thomas D

      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.

      1 Reply Last reply Reply Quote 0
      • Daniel Mulroy
        Daniel Mulroy last edited by

        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

        T 1 Reply Last reply Reply Quote 0
        • T
          Thomas D @Daniel Mulroy last edited by

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

          1 Reply Last reply Reply Quote 0
          • Daniel Mulroy
            Daniel Mulroy last edited by

            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!

            T 1 Reply Last reply Reply Quote 3
            • T
              Thomas D @Daniel Mulroy last edited by Thomas D

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

              1 Reply Last reply Reply Quote 0
              • Daniel Mulroy
                Daniel Mulroy last edited by

                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 ๐Ÿ™‚

                T 1 Reply Last reply Reply Quote 0
                • T
                  Thomas D @Daniel Mulroy last edited by Thomas D

                  @Daniel-Mulroy

                  Wanted to detect the country so I can apply the correct language automatically.

                  @Wassim Maybe that is already done?

                  Google seem to be very picky about localization:

                  https://developers.google.com/search/docs/advanced/crawling/managing-multi-regional-sites

                  1 Reply Last reply Reply Quote 0
                  • Wassim
                    Wassim last edited by

                    @Thomas-Djรคrf said in Retrieve visitor country code?:

                    Wanted to detect the country so I can apply the correct language automatically.

                    Yes language is automatically detected and a cookie "lng" is set. Then it depends on your page translations from the page builder.

                    T 1 Reply Last reply Reply Quote 0
                    • T
                      Thomas D @Wassim last edited by

                      @Wassim

                      Super, then I don't need to worry about that โœŒ

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post