Skip to content

Commit

Permalink
Merge pull request dubinc#1071 from dubinc/get-final-url
Browse files Browse the repository at this point in the history
Add `getFinalUrl` for deep links & link cloaking
  • Loading branch information
steven-tey authored Jul 16, 2024
2 parents 85ef531 + 5a8ee59 commit 3967d57
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions apps/web/lib/middleware/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,15 @@ export default async function LinkMiddleware(
// rewrite to deeplink page if the link is a mailto: or tel:
} else if (isSupportedDeeplinkProtocol(url)) {
return NextResponse.rewrite(
new URL(`/deeplink/${encodeURIComponent(url)}`, req.url),
new URL(
`/deeplink/${encodeURIComponent(
getFinalUrl(url, {
req,
clickId: trackConversion ? clickId : undefined,
}),
)}`,
req.url,
),
{
headers: {
...DUB_HEADERS,
Expand All @@ -240,7 +248,15 @@ export default async function LinkMiddleware(
} else if (rewrite) {
if (iframeable) {
return NextResponse.rewrite(
new URL(`/cloaked/${encodeURIComponent(url)}`, req.url),
new URL(
`/cloaked/${encodeURIComponent(
getFinalUrl(url, {
req,
clickId: trackConversion ? clickId : undefined,
}),
)}`,
req.url,
),
{
headers: {
...DUB_HEADERS,
Expand Down

0 comments on commit 3967d57

Please sign in to comment.