Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from allowedQueryParams to blockedQueryParams #1280

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions apps/web/lib/middleware/utils/get-final-url.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { NextRequest } from "next/server";

// Only add query params to the final URL if they are in this list
const allowedQueryParams = [
"utm_source",
"utm_medium",
"utm_campaign",
"utm_term",
"utm_content",
"ref",
];

export const getFinalUrl = (
url: string,
{ req, clickId }: { req: NextRequest; clickId?: string },
Expand Down Expand Up @@ -42,6 +32,16 @@ export const getFinalUrl = (
return urlObj.toString();
};

// Only add query params to the final URL if they are not in this list
const blockedQueryParams = [
"fbclid",
"dub_id",
"dclid",
"gclid",
"gclsrc",
"trk",
];

// Get final cleaned url for storing in TB
export const getFinalUrlForRecordClick = ({
req,
Expand All @@ -53,10 +53,10 @@ export const getFinalUrlForRecordClick = ({
const searchParams = req.nextUrl.searchParams;
const urlObj = new URL(url);

// Filter out query params that are not in the allowed list
// Filter out query params that are in the blocked list
if (searchParams.size > 0) {
for (const [key, value] of searchParams) {
if (allowedQueryParams.includes(key)) {
if (!blockedQueryParams.includes(key)) {
urlObj.searchParams.set(key, value);
}
}
Expand Down
Loading