Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(analytics): send first-view email for anonymous viewers with no session

Richie McIlroyc1ec572d24a2
diff --git a/apps/web/app/api/analytics/track/route.ts b/apps/web/app/api/analytics/track/route.ts
index 6b4288445..52fb22e95 100644
--- a/apps/web/app/api/analytics/track/route.ts
+++ b/apps/web/app/api/analytics/track/route.ts
@@ -192,6 +192,23 @@ export async function POST(request: NextRequest) {
]),
);
}
+
+ if (!userId && !sessionId) {
+ yield* Effect.forkDaemon(
+ Effect.tryPromise(() =>
+ sendFirstViewEmail({
+ videoId: body.videoId,
+ viewerName: "Anonymous Viewer",
+ isAnonymous: true,
+ }),
+ ).pipe(
+ Effect.catchAll((error) => {
+ console.error("Failed to send first view email:", error);
+ return Effect.void;
+ }),
+ ),
+ );
+ }
}).pipe(provideOptionalAuth),
);