Download frontend/src/lib/clip-export-tracking.ts from new-arc/vector: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/clip-export-tracking.ts
- Command line
-
hf download hf://spaces/new-arc/vector/frontend/src/lib/clip-export-tracking.ts
-
curl -L -o clip-export-tracking.ts https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/clip-export-tracking.ts
1.48 kB
| "use client"; | |
| import { attributionMetadata, getAccountAttribution } from "@/lib/attribution"; | |
| import { track } from "@/lib/datafast"; | |
| export type ClipExportSurface = "task" | "editor" | "editor_queue"; | |
| /** | |
| * Records a clip export. Every export sends `clip_exported`; the user's first | |
| * export also sends `first_clip_exported` with the server-stored attribution, | |
| * so activation can be credited to the campaign even across devices. Only the | |
| * exporting account's own attribution (confirmed, or claimed and pending) is attached. | |
| */ | |
| export async function trackClipExport({ userId, ...details }: { userId: string; surface: ClipExportSurface; format: string }) { | |
| const accountMetadata = attributionMetadata(getAccountAttribution(userId)); | |
| track("clip_exported", { ...details, ...accountMetadata }); | |
| try { | |
| const response = await fetch("/api/attribution/clip-export", { method: "POST", keepalive: true }); | |
| if (!response.ok) return; | |
| const result = await response.json(); | |
| if (!result?.first_export) return; | |
| // An export can land before sign-up attribution syncs; fall back to this account's claimed visit. | |
| const serverMetadata = attributionMetadata(result.attribution); | |
| track("first_clip_exported", { | |
| ...details, | |
| ...(Object.keys(serverMetadata).length > 0 ? serverMetadata : accountMetadata), | |
| hours_since_signup: result.hours_since_signup, | |
| }); | |
| } catch { | |
| // Tracking must never interfere with the download itself. | |
| } | |
| } | |