diff --git a/app/sponsor/page.tsx b/app/sponsor/page.tsx index 1192ae9..6cd3c66 100644 --- a/app/sponsor/page.tsx +++ b/app/sponsor/page.tsx @@ -1,7 +1,7 @@ import type { Metadata } from "next"; import { unstable_cache } from "next/cache"; import { getSupabaseAdmin } from "@/lib/supabase"; -import { ownerTrafficSnapshot, parseSponsorTraffic } from "@/lib/sponsorship-analytics"; +import { parseSponsorTraffic } from "@/lib/sponsorship-analytics"; import { PartnerPage } from "@/components/partner-page"; export const metadata: Metadata = { @@ -41,5 +41,5 @@ export default async function PartnerRoute({ searchParams }: PartnerRouteProps) const now = new Date(); const traffic = parseSponsorTraffic(await getCachedAudience(), now); - return ; + return ; } diff --git a/components/partner-page.tsx b/components/partner-page.tsx index 91a079c..9fbf7a0 100644 --- a/components/partner-page.tsx +++ b/components/partner-page.tsx @@ -1,9 +1,11 @@ import { Navbar } from "@/components/navbar"; import { PartnerCheckoutForm } from "@/components/partner-checkout-form"; import { SPONSOR_CONTACT, sponsorshipMonthLabel } from "@/lib/sponsorship-config"; -import { formatMonthlyVisitors, trafficPeriodLabel, type SponsorTraffic } from "@/lib/sponsorship-analytics"; +import { formatMonthlyVisitors, ownerTrafficSnapshot, snapshotReportedMonth, trafficPeriodLabel, type SponsorTraffic } from "@/lib/sponsorship-analytics"; -export function PartnerPage({ checkoutStatus, traffic = null, liveTraffic = false }: { checkoutStatus?: "success" | "cancelled"; traffic?: SponsorTraffic | null; liveTraffic?: boolean }) { +export function PartnerPage({ checkoutStatus, traffic = null }: { checkoutStatus?: "success" | "cancelled"; traffic?: SponsorTraffic | null }) { + const snapshot = ownerTrafficSnapshot(); + const snapshotMonth = snapshotReportedMonth(snapshot); const monthLabel = sponsorshipMonthLabel(new Date()); return (
@@ -15,9 +17,9 @@ export function PartnerPage({ checkoutStatus, traffic = null, liveTraffic = fals

A small, clearly labeled spot for your product, where developers reverse-engineer codebases and websites.

250K+
Lifetime visitors
-
{traffic ? formatMonthlyVisitors(traffic.visitors) : "—"}
visitors last month
+
{formatMonthlyVisitors(traffic?.visitors ?? snapshot.visitors)}
{traffic ? "visitors last month" : "Monthly visitors"}
-

{liveTraffic ? "Monthly traffic updates hourly" : traffic ? "Audience snapshot · October 2026" : "Monthly traffic temporarily unavailable"}

+

{traffic ? "Monthly traffic updates hourly" : `Audience snapshot · ${snapshotMonth}`}

Previous sponsors

diff --git a/lib/sponsorship-analytics.ts b/lib/sponsorship-analytics.ts index daf7de0..79c6cde 100644 --- a/lib/sponsorship-analytics.ts +++ b/lib/sponsorship-analytics.ts @@ -12,19 +12,20 @@ export function previousCalendarMonth(now: Date) { }; } -/** The owner supplied this historical snapshot; it is never rolled into a different month. */ -export function ownerTrafficSnapshot(now: Date): SponsorTraffic | null { - const { start } = previousCalendarMonth(now); - return start.toISOString() === "2026-09-01T00:00:00.000Z" ? { - visitors: 35000, - periodStart: "2026-09-01T00:00:00.000Z", - periodEnd: "2026-10-01T00:00:00.000Z", - measuredAt: "2026-10-08T07:32:00.000Z", - } : null; +/** Owner-reported monthly audience, dated when supplied rather than assigned an unverified period. */ +export function ownerTrafficSnapshot() { + return { + visitors: 44256, + reportedAt: "2026-11-09T00:00:00.000Z", + }; } export function formatMonthlyVisitors(visitors: number) { - return new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 0 }).format(visitors); + return new Intl.NumberFormat("en-US").format(visitors); +} + +export function snapshotReportedMonth(snapshot: ReturnType) { + return new Intl.DateTimeFormat("en-US", { month: "long", year: "numeric", timeZone: "UTC" }).format(new Date(snapshot.reportedAt)); } export function trafficPeriodLabel(traffic: SponsorTraffic) { diff --git a/tests/sponsorship-analytics.test.ts b/tests/sponsorship-analytics.test.ts index e772c07..b86c346 100644 --- a/tests/sponsorship-analytics.test.ts +++ b/tests/sponsorship-analytics.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import test from "node:test"; -import { formatMonthlyVisitors, ownerTrafficSnapshot, parseSponsorTraffic, previousCalendarMonth } from "../lib/sponsorship-analytics"; +import { formatMonthlyVisitors, ownerTrafficSnapshot, parseSponsorTraffic, previousCalendarMonth, snapshotReportedMonth } from "../lib/sponsorship-analytics"; const now = new Date("2026-10-08T08:00:00Z"); const row = {window_key:"previous_calendar_month",window_start:"2026-09-01T00:00:00Z",window_end:"2026-10-01T00:00:00Z",daily_unique_visits:35087,missing_device_events:0,measured_at:"2026-10-08T07:43:00Z"}; @@ -8,16 +8,25 @@ test("previous complete calendar month handles year rollover", () => { assert.equal(previousCalendarMonth(new Date("2027-01-01T00:00:00Z")).start.toISOString(), "2026-12-01T00:00:00.000Z"); }); -test("monthly traffic displays 35K and never relabels last month's stale period", () => { +test("monthly traffic displays exact counts and never relabels last month's stale period", () => { const result = parseSponsorTraffic([row],now); assert.equal(result?.visitors,35087); - assert.equal(formatMonthlyVisitors(result!.visitors),"35K"); + assert.equal(formatMonthlyVisitors(result!.visitors),"35,087"); assert.equal(parseSponsorTraffic([row],new Date("2026-11-01T00:00:00Z")),null); - assert.equal(ownerTrafficSnapshot(now)?.visitors,35000); - assert.equal(ownerTrafficSnapshot(new Date("2026-11-01T00:00:00Z")),null); }); test("monthly analytics rejects errors, unsafe numbers, missing identifiers and stale measurements", () => { for (const value of [null,{},[],[{...row,daily_unique_visits:-1}],[{...row,daily_unique_visits:null}],[{...row,daily_unique_visits:""}],[{...row,daily_unique_visits:"NaN"}],[{...row,missing_device_events:1}],[{...row,measured_at:"2026-10-06T00:00:00Z"}],[{...row,window_start:"2026-08-01T00:00:00Z"}],[{...row,window_key:"rolling_30_days"}]]) assert.equal(parseSponsorTraffic(value,now),null); assert.equal(parseSponsorTraffic([{...row,daily_unique_visits:0}],now)?.visitors,0); }); + +test("owner-reported monthly audience keeps the exact count and its supplied date", () => { + const snapshot = ownerTrafficSnapshot(); + assert.equal(snapshot.visitors, 44256); + assert.equal(formatMonthlyVisitors(snapshot.visitors), "44,256"); + assert.equal(snapshot.reportedAt, "2026-11-09T00:00:00.000Z"); + assert.equal(snapshotReportedMonth(snapshot), "November 2026"); + // A reported snapshot has no invented calendar-month range or automatic expiry. + assert.equal("periodStart" in snapshot, false); + assert.equal("periodEnd" in snapshot, false); +});