Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions frontend/src/actions/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use server";

import { getMongoClientPromise } from "@/lib/mongodb";

const COLLECTION = "job_apply_clicks";

export async function trackApplyClick(job: {
jobId: string;
jobTitle: string;
companyName: string;
}) {
try {
const client = await getMongoClientPromise();
const db = client.db();
await db.collection(COLLECTION).insertOne({
jobId: job.jobId,
jobTitle: job.jobTitle,
companyName: job.companyName,
clickedAt: new Date(),
});
} catch {
// Non-critical — don't surface tracking errors to the user
}
}
14 changes: 14 additions & 0 deletions frontend/src/components/jobs/job-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import JobDetailsLoading from "@/components/layout/job-details-loading";
import JobSummary from "@/components/jobs/job-summary";
import { upsertLocalStartedApplication } from "@/lib/local-applications";
import { addApplication } from "@/app/my-applications/actions";
import { trackApplyClick } from "@/actions/analytics";
import { sendGAEvent } from "@next/third-parties/google";
import Link from "next/link";
import { useSession } from "next-auth/react";

Expand Down Expand Up @@ -50,6 +52,18 @@ export default function JobDetails() {
const handleApplyClick = () => {
window.open(selectedJob.application_url, "_blank");

trackApplyClick({
jobId: selectedJob.id,
jobTitle: selectedJob.title,
companyName: selectedJob.company?.name || "Unknown",
});

sendGAEvent("event", "apply_click", {
job_id: selectedJob.id,
job_title: selectedJob.title,
company: selectedJob.company?.name || "Unknown",
});

if (session?.user) {
addApplication(selectedJob.id, {
jobId: selectedJob.id,
Expand Down
Loading