From 30805b7bb94399d8c4d29d2679ff49278e05652c Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Wed, 27 Aug 2025 13:25:21 +0200 Subject: [PATCH] Remove custom analytics in favor of Vercel defaults The changes remove custom analytics tracking in favor of using Vercel's default page view tracking functionality. --- src/app/api/publications/[filename]/route.ts | 51 +-------- src/app/publications/page.tsx | 66 +---------- src/lib/analytics.ts | 113 +------------------ 3 files changed, 9 insertions(+), 221 deletions(-) diff --git a/src/app/api/publications/[filename]/route.ts b/src/app/api/publications/[filename]/route.ts index bade654..a3b4dc8 100644 --- a/src/app/api/publications/[filename]/route.ts +++ b/src/app/api/publications/[filename]/route.ts @@ -1,6 +1,4 @@ import { NextRequest, NextResponse } from "next/server"; -import { track } from "@vercel/analytics/server"; -import { parseBibtex } from "~/lib/bibtex"; import { readFile } from "fs/promises"; import { join } from "path"; @@ -16,47 +14,7 @@ export async function GET( } try { - // Read the BibTeX file to get publication metadata - const bibtexPath = join(process.cwd(), "public", "publications.bib"); - const bibtexContent = await readFile(bibtexPath, "utf-8"); - const publications = parseBibtex(bibtexContent); - - // Find the publication that matches this PDF - const publication = publications.find( - (pub) => - pub.paperUrl?.includes(filename) || - pub.posterUrl?.includes(filename) || - pub.slidesUrl?.includes(filename), - ); - - // Track the PDF access - if (publication) { - const isPoster = publication.posterUrl?.includes(filename); - const isSlides = publication.slidesUrl?.includes(filename); - - let fileType = "paper"; - if (isPoster) fileType = "poster"; - if (isSlides) fileType = "slides"; - - await track("Publication PDF Access", { - title: publication.title, - type: publication.type, - year: publication.year.toString(), - pdf_type: fileType, - citation_key: publication.citationKey || "", - venue: publication.venue || "", - access_method: "direct_url", - filename: filename, - }); - } else { - // Track unknown PDF access - await track("Unknown PDF Access", { - filename: filename, - access_method: "direct_url", - }); - } - - // Serve the PDF file + // Serve the PDF file directly - Vercel Analytics will automatically track the route access const pdfPath = join(process.cwd(), "public", "publications", filename); const pdfBuffer = await readFile(pdfPath); @@ -69,13 +27,6 @@ export async function GET( }); } catch (error) { console.error("Error serving PDF:", error); - - // Track the error - await track("PDF Access Error", { - filename: filename, - error: error instanceof Error ? error.message : "Unknown error", - }); - return new NextResponse("PDF not found", { status: 404 }); } } diff --git a/src/app/publications/page.tsx b/src/app/publications/page.tsx index 8f54862..2f4eca8 100644 --- a/src/app/publications/page.tsx +++ b/src/app/publications/page.tsx @@ -22,12 +22,7 @@ import { Skeleton } from "~/components/ui/skeleton"; import { CardSkeleton } from "~/components/ui/skeletons"; import type { Publication } from "~/lib/bibtex"; import { parseBibtex } from "~/lib/bibtex"; -import { - trackPdfView, - trackDoiClick, - trackBibtexDownload, - trackSlidesView, -} from "~/lib/analytics"; +// No custom tracking needed - Vercel automatically tracks page views export default function PublicationsPage() { const [publications, setPublications] = useState([]); @@ -45,15 +40,6 @@ export default function PublicationsPage() { }, []); const downloadBibtex = (pub: Publication) => { - // Track the BibTeX download - trackBibtexDownload({ - publicationTitle: pub.title, - publicationType: pub.type, - publicationYear: pub.year, - citationKey: pub.citationKey, - venue: pub.venue, - }); - const { title, authors, @@ -95,50 +81,7 @@ export default function PublicationsPage() { URL.revokeObjectURL(url); }; - const handlePaperClick = (pub: Publication) => { - trackPdfView({ - publicationTitle: pub.title, - publicationType: pub.type, - publicationYear: pub.year, - citationKey: pub.citationKey, - venue: pub.venue, - pdfType: "paper", - }); - }; - - const handlePosterClick = (pub: Publication) => { - trackPdfView({ - publicationTitle: pub.title, - publicationType: pub.type, - publicationYear: pub.year, - citationKey: pub.citationKey, - venue: pub.venue, - pdfType: "poster", - }); - }; - - const handleDoiClick = (pub: Publication) => { - if (pub.doi) { - trackDoiClick({ - publicationTitle: pub.title, - publicationType: pub.type, - publicationYear: pub.year, - citationKey: pub.citationKey, - venue: pub.venue, - doi: pub.doi, - }); - } - }; - - const handleSlidesClick = (pub: Publication) => { - trackSlidesView({ - publicationTitle: pub.title, - publicationType: pub.type, - publicationYear: pub.year, - citationKey: pub.citationKey, - venue: pub.venue, - }); - }; + // No custom click handlers needed - Vercel automatically tracks API route access return (
@@ -179,7 +122,6 @@ export default function PublicationsPage() { target="_blank" rel="noopener noreferrer" className="text-muted-foreground hover:text-primary sm:flex-shrink-0" - onClick={() => handlePaperClick(pub)} > @@ -222,7 +164,6 @@ export default function PublicationsPage() { href={`https://doi.org/${pub.doi}`} target="_blank" rel="noopener noreferrer" - onClick={() => handleDoiClick(pub)} > handlePaperClick(pub)} > handlePosterClick(pub)} > handleSlidesClick(pub)} > , -) { - track("BibTeX Download", { - title: data.publicationTitle, - type: data.publicationType, - year: data.publicationYear.toString(), - citation_key: data.citationKey || "", - venue: data.venue || "", - }); -} - -/** - * Track PDF views (paper or poster) - */ -export function trackPdfView( - data: Omit & { - pdfType: "paper" | "poster"; - }, -) { - track("Publication PDF Click", { - title: data.publicationTitle, - type: data.publicationType, - year: data.publicationYear.toString(), - pdf_type: data.pdfType, - citation_key: data.citationKey || "", - venue: data.venue || "", - }); -} - -/** - * Track DOI clicks - */ -export function trackDoiClick( - data: Omit & { doi: string }, -) { - track("DOI Link Click", { - title: data.publicationTitle, - type: data.publicationType, - year: data.publicationYear.toString(), - doi: data.doi, - citation_key: data.citationKey || "", - venue: data.venue || "", - }); -} - -/** - * Track slides clicks - user intent/engagement - */ -export function trackSlidesView( - data: Omit, -) { - track("Publication Slides Click", { - title: data.publicationTitle, - type: data.publicationType, - year: data.publicationYear.toString(), - citation_key: data.citationKey || "", - venue: data.venue || "", - }); -} +// No custom tracking functions needed - Vercel automatically tracks all page views +// including API route access at /api/publications/[filename]