zamson
December 4, 2022, 2:31am
1
I’m trying to determine which country a visitor comes from in my Gatsby app and setting the parameter value as a cookie. Understand there should be a “x-country” header available but it seems the header is not being sent when connecting to my app.
Any help would be appreciated.
zamson
December 4, 2022, 6:55am
2
Solved this by setting a cookie with a edge function context.geo.country?.code
Could you please share the function code?
zamson
March 16, 2023, 2:17am
4
Sorry, did not see your reply. I’m sure you solved it by now but will leave my solution here for anyone else looking:
country-code.js
export default async (request, context) => {
const countryCode = context.geo?.country?.code
const url = new URL(request.url)
if (!context.cookies.get('country')) {
context.cookies.set({
name: 'country',
value: countryCode,
path: '/',
secure: true,
This file has been truncated. show original
netlify.toml
[[edge_functions]]
function = "country-code"
path = "/*"
SamO
March 16, 2023, 12:19pm
5
Thanks for sharing zamson. (:
1 Like