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.

cacheIdentityHashClicks → cacheDeepLinkClickData

Steven Tey55d39a55ce74
diff --git a/apps/web/app/(ee)/api/track/open/route.ts b/apps/web/app/(ee)/api/track/open/route.ts
index 965d54d156..95a77c1c6d 100644
--- a/apps/web/app/(ee)/api/track/open/route.ts
+++ b/apps/web/app/(ee)/api/track/open/route.ts
@@ -2,8 +2,7 @@ import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
import { linkCache } from "@/lib/api/links/cache";
import { recordClickCache } from "@/lib/api/links/record-click-cache";
import { parseRequestBody } from "@/lib/api/utils";
-import { getIdentityHash } from "@/lib/middleware/utils";
-import { IdentityHashClicksData } from "@/lib/middleware/utils/cache-identity-hash-clicks";
+import { DeepLinkClickData } from "@/lib/middleware/utils/cache-deeplink-click-data";
import { getLinkViaEdge } from "@/lib/planetscale";
import { recordClick } from "@/lib/tinybird";
import { RedisLinkProps } from "@/lib/types";
@@ -56,16 +55,17 @@ export const POST = withAxiom(async (req: AxiomRequest) => {
);
if (!deepLinkUrl) {
- const identityHash = await getIdentityHash(req);
+ const ip = ipAddress(req);
+ console.log(`Checking cache for ${ip}:${dubDomain}:*`);
// Get all iOS click cache keys for this identity hash
const [_, cacheKeysForDomain] = await redis.scan(0, {
- match: `iosClickCache:${identityHash}:${dubDomain}:*`,
+ match: `deepLinkClickCache:${ip}:${dubDomain}:*`,
count: 10,
});
if (cacheKeysForDomain.length > 0) {
- const cachedData = await redis.get<IdentityHashClicksData>(
+ const cachedData = await redis.get<DeepLinkClickData>(
cacheKeysForDomain[0],
);
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 16d0842286..073f4970ef 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -31,7 +31,7 @@ import { recordClickCache } from "../api/links/record-click-cache";
import { getLinkViaEdge } from "../planetscale";
import { getDomainViaEdge } from "../planetscale/get-domain-via-edge";
import { getPartnerAndDiscount } from "../planetscale/get-partner-discount";
-import { cacheIdentityHashClicks } from "./utils/cache-identity-hash-clicks";
+import { cacheDeepLinkClickData } from "./utils/cache-deeplink-click-data";
import { crawlBitly } from "./utils/crawl-bitly";
import { isSingularTrackingUrl } from "./utils/is-singular-tracking-url";
import { resolveABTestURL } from "./utils/resolve-ab-test-url";
@@ -410,7 +410,7 @@ export default async function LinkMiddleware(
}),
// cache click if it's an iOS app store URL
ios.startsWith("https://apps.apple.com/") &&
- cacheIdentityHashClicks({
+ cacheDeepLinkClickData({
req,
clickId,
link: {
diff --git a/apps/web/lib/middleware/utils/cache-identity-hash-clicks.ts b/apps/web/lib/middleware/utils/cache-deeplink-click-data.ts
similarity index 52%
rename from apps/web/lib/middleware/utils/cache-identity-hash-clicks.ts
rename to apps/web/lib/middleware/utils/cache-deeplink-click-data.ts
index 725fce414e..61c9cf94a6 100644
--- a/apps/web/lib/middleware/utils/cache-identity-hash-clicks.ts
+++ b/apps/web/lib/middleware/utils/cache-deeplink-click-data.ts
@@ -1,12 +1,12 @@
import { redis } from "@/lib/upstash";
-import { getIdentityHash } from "./get-identity-hash";
+import { ipAddress } from "@vercel/functions";
-export type IdentityHashClicksData = {
+export type DeepLinkClickData = {
clickId: string;
link: { id: string; domain: string; key: string; url: string };
};
-export async function cacheIdentityHashClicks({
+export async function cacheDeepLinkClickData({
req,
clickId,
link,
@@ -15,9 +15,9 @@ export async function cacheIdentityHashClicks({
clickId: string;
link: { id: string; domain: string; key: string; url: string };
}) {
- const identityHash = await getIdentityHash(req);
- return await redis.set<IdentityHashClicksData>(
- `iosClickCache:${identityHash}:${link.domain}:${link.key}`,
+ const ip = ipAddress(req);
+ return await redis.set<DeepLinkClickData>(
+ `deepLinkClickCache:${ip}:${link.domain}:${link.key}`,
{
clickId,
link,