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.

move trackLead to inside Promise.allSettled

Steven Tey0b9a45c0930c
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index 269d86b213..8564952ed4 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -17,12 +17,12 @@ import CredentialsProvider from "next-auth/providers/credentials";
import EmailProvider from "next-auth/providers/email";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
-import { cookies } from "next/headers";
import {
exceededLoginAttemptsThreshold,
incrementLoginAttempts,
} from "./lock-account";
import { validatePassword } from "./password";
+import { trackLead } from "./track-lead";
const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
@@ -448,42 +448,10 @@ export const authOptions: NextAuthOptions = {
scheduledAt: new Date(Date.now() + 5 * 60 * 1000).toISOString(),
marketing: true,
}),
+ trackLead(user),
]),
);
}
-
- const clickId =
- cookies().get("dub_id")?.value || cookies().get("dclid")?.value;
- if (clickId) {
- // send lead event to Dub
- waitUntil(
- // dub.track.lead({
- // clickId,
- // eventName: "Sign Up",
- // customerId: user.id,
- // customerName: user.name,
- // customerEmail: user.email,
- // customerAvatar: user.image,
- // }),
- fetch("https://api.dub.co/track/lead", {
- method: "POST",
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- clickId,
- eventName: "Sign Up",
- customerId: user.id,
- customerName: user.name,
- customerEmail: user.email,
- customerAvatar: user.image,
- }),
- }).then((res) => res.json()),
- );
- // delete the clickId cookie
- cookies().delete("dub_id");
- }
}
// lazily backup user avatar to R2
const currentImage = message.user.image;
diff --git a/apps/web/lib/auth/track-lead.ts b/apps/web/lib/auth/track-lead.ts
new file mode 100644
index 0000000000..6141a74716
--- /dev/null
+++ b/apps/web/lib/auth/track-lead.ts
@@ -0,0 +1,40 @@
+import { User } from "next-auth";
+import { cookies } from "next/headers";
+
+export const trackLead = async (user: User) => {
+ const clickId =
+ cookies().get("dub_id")?.value || cookies().get("dclid")?.value;
+
+ if (!clickId) {
+ console.log("No clickId cookie found, skipping lead tracking...");
+ return;
+ }
+
+ // dub.track.lead({
+ // clickId,
+ // eventName: "Sign Up",
+ // customerId: user.id,
+ // customerName: user.name,
+ // customerEmail: user.email,
+ // customerAvatar: user.image,
+ // }),
+ await fetch("https://api.dub.co/track/lead", {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${process.env.DUB_API_KEY}`,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ clickId,
+ eventName: "Sign Up",
+ customerId: user.id,
+ customerName: user.name,
+ customerEmail: user.email,
+ customerAvatar: user.image,
+ }),
+ }).then((res) => res.json());
+
+ // delete the clickId cookie
+ cookies().delete("dclid");
+ cookies().delete("dub_id");
+};