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.
This commit is contained in:
2025-08-27 13:25:21 +02:00
parent 9bac3cf33c
commit 30805b7bb9
3 changed files with 9 additions and 221 deletions
+1 -50
View File
@@ -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 });
}
}
+2 -64
View File
@@ -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<Publication[]>([]);
@@ -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 (
<div className="space-y-6">
@@ -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)}
>
<ArrowUpRight className="h-5 w-5" />
</Link>
@@ -222,7 +164,6 @@ export default function PublicationsPage() {
href={`https://doi.org/${pub.doi}`}
target="_blank"
rel="noopener noreferrer"
onClick={() => handleDoiClick(pub)}
>
<Badge
variant="secondary"
@@ -238,7 +179,6 @@ export default function PublicationsPage() {
href={pub.paperUrl}
target="_blank"
rel="noopener noreferrer"
onClick={() => handlePaperClick(pub)}
>
<Badge
variant="secondary"
@@ -254,7 +194,6 @@ export default function PublicationsPage() {
href={pub.posterUrl}
target="_blank"
rel="noopener noreferrer"
onClick={() => handlePosterClick(pub)}
>
<Badge
variant="secondary"
@@ -270,7 +209,6 @@ export default function PublicationsPage() {
href={pub.slidesUrl}
target="_blank"
rel="noopener noreferrer"
onClick={() => handleSlidesClick(pub)}
>
<Badge
variant="secondary"