mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-29 18:00:26 -06:00
feat: add country location to response metadata (#1892)
This commit is contained in:
committed by
GitHub
parent
1635297226
commit
ad63be3005
@@ -1,6 +1,7 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { sendToPipeline } from "@/app/lib/pipelines";
|
||||
import { headers } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
import { UAParser } from "ua-parser-js";
|
||||
|
||||
@@ -22,6 +23,7 @@ export async function POST(request: Request): Promise<NextResponse> {
|
||||
responseInput.personId = null;
|
||||
}
|
||||
const agent = UAParser(request.headers.get("user-agent"));
|
||||
const country = headers().get("CF-IPCountry") || headers().get("X-Vercel-IP-Country") || undefined;
|
||||
const inputValidation = ZResponseLegacyInput.safeParse(responseInput);
|
||||
|
||||
if (!inputValidation.success) {
|
||||
@@ -60,6 +62,7 @@ export async function POST(request: Request): Promise<NextResponse> {
|
||||
device: agent?.device.type,
|
||||
os: agent?.os.name,
|
||||
},
|
||||
country: country,
|
||||
};
|
||||
|
||||
// check if personId is anonymous
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { sendToPipeline } from "@/app/lib/pipelines";
|
||||
import { headers } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
import { UAParser } from "ua-parser-js";
|
||||
|
||||
@@ -45,6 +46,7 @@ export async function POST(request: Request, context: Context): Promise<NextResp
|
||||
}
|
||||
|
||||
const agent = UAParser(request.headers.get("user-agent"));
|
||||
const country = headers().get("CF-IPCountry") || headers().get("X-Vercel-IP-Country") || undefined;
|
||||
const inputValidation = ZResponseInput.safeParse({ ...responseInput, environmentId });
|
||||
|
||||
if (!inputValidation.success) {
|
||||
@@ -83,6 +85,7 @@ export async function POST(request: Request, context: Context): Promise<NextResp
|
||||
device: agent?.device.type,
|
||||
os: agent?.os.name,
|
||||
},
|
||||
country: country,
|
||||
};
|
||||
|
||||
response = await createResponse({
|
||||
|
||||
@@ -45,6 +45,7 @@ export const ZResponseMeta = z.object({
|
||||
device: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
country: z.string().optional(),
|
||||
});
|
||||
|
||||
export type TResponseMeta = z.infer<typeof ZResponseMeta>;
|
||||
@@ -86,6 +87,7 @@ export const ZResponseInput = z.object({
|
||||
os: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
country: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
@@ -209,6 +209,7 @@ export default function SingleResponseCard({
|
||||
</p>
|
||||
)}
|
||||
{response.meta?.source && <p>Source: {response.meta.source}</p>}
|
||||
{response.meta?.country && <p>Country: {response.meta.country}</p>}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user