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.

Create get-top-domains-for-links.ts

Steven Tey07c028742064
diff --git a/apps/web/scripts/get-top-domains-for-links.ts b/apps/web/scripts/get-top-domains-for-links.ts
new file mode 100644
index 0000000000..fe53e32cde
--- /dev/null
+++ b/apps/web/scripts/get-top-domains-for-links.ts
@@ -0,0 +1,29 @@
+import { prisma } from "@dub/prisma";
+import { LEGAL_USER_ID, LEGAL_WORKSPACE_ID } from "@dub/utils";
+import "dotenv-flow/config";
+
+async function main() {
+ const topDomains = (await prisma.$queryRaw`
+ SELECT
+ SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(REPLACE(url, 'https://', ''), 'http://', ''), '/', 1), '?', 1) as domain,
+ COUNT(*) as count
+ FROM Link
+ WHERE
+ projectId IS NOT NULL
+ AND projectId != ${LEGAL_WORKSPACE_ID}
+ AND userId IS NOT NULL
+ AND userId != ${LEGAL_USER_ID}
+ AND url NOT LIKE 'https%3A%2F%2F%'
+ GROUP BY SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(REPLACE(url, 'https://', ''), 'http://', ''), '/', 1), '?', 1)
+ HAVING count >= 5
+ ORDER BY count DESC
+ `) as { domain: string; count: number }[];
+
+ console.log(`Found ${topDomains.length} top domains`);
+ console.table(topDomains);
+ console.log(`"${topDomains.map(({ domain }) => domain).join('", "')}"`);
+
+ await prisma.$disconnect();
+}
+
+main();