Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

track referrer if passed

Steven Teydb5f0dc077a8
diff --git a/apps/web/app/api/track/visit/route.ts b/apps/web/app/api/track/visit/route.ts
index ef49ac5e41..4e04341f11 100644
--- a/apps/web/app/api/track/visit/route.ts
+++ b/apps/web/app/api/track/visit/route.ts
@@ -30,9 +30,9 @@ const CORS_HEADERS = {
export const POST = withAxiom(
async (req: AxiomRequest) => {
try {
- const { domain, url } = await parseRequestBody(req);
+ const { domain, url, referrer } = await parseRequestBody(req);
- if (!domain || url) {
+ if (!domain || !url) {
throw new DubApiError({
code: "bad_request",
message: "Missing domain or url",
@@ -124,6 +124,7 @@ export const POST = withAxiom(
url: finalUrl,
skipRatelimit: true,
workspaceId: link.projectId,
+ ...(referrer && { referrer }),
}),
);
}
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.ts
index 5f3bb9c59d..7833e4816f 100644
--- a/apps/web/lib/tinybird/record-click.ts
+++ b/apps/web/lib/tinybird/record-click.ts
@@ -33,6 +33,7 @@ export async function recordClick({
skipRatelimit,
workspaceId,
timestamp,
+ referrer,
}: {
req: Request;
linkId: string;
@@ -42,6 +43,7 @@ export async function recordClick({
skipRatelimit?: boolean;
workspaceId: string | undefined;
timestamp?: string;
+ referrer?: string;
}) {
const searchParams = new URL(req.url).searchParams;
@@ -89,7 +91,7 @@ export async function recordClick({
const isEuCountry = geo.country && EU_COUNTRY_CODES.includes(geo.country);
const ua = userAgent(req);
- const referer = req.headers.get("referer");
+ const referer = referrer || req.headers.get("referer");
const identity_hash = await getIdentityHash(req);