2026-11-19 09:26:06 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reports a visit of the share page from the visitor's browser. Link preview
|
|
|
|
|
* robots do not run scripts, so only people are counted (the backend also
|
|
|
|
|
* leaves out the sharer).
|
|
|
|
|
*/
|
|
|
|
|
export function ShareVisit({ slug }: { slug: string }) {
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const key = `share-visit:${slug}`;
|
2026-11-19 11:24:49 +00:00
|
|
|
try {
|
|
|
|
|
// If they sign up later, the sharer who brought them is remembered.
|
|
|
|
|
localStorage.setItem("sf_ref", slug);
|
|
|
|
|
} catch {
|
|
|
|
|
// storage blocked
|
|
|
|
|
}
|
2026-11-19 09:26:06 +00:00
|
|
|
try {
|
|
|
|
|
if (sessionStorage.getItem(key)) return;
|
|
|
|
|
sessionStorage.setItem(key, "1");
|
|
|
|
|
} catch {
|
|
|
|
|
// storage blocked: report anyway
|
|
|
|
|
}
|
|
|
|
|
fetch(`/api/v1/public/shares/${slug}/visit`, { method: "POST", credentials: "same-origin" }).catch(() => {});
|
|
|
|
|
}, [slug]);
|
|
|
|
|
return null;
|
|
|
|
|
}
|