-
Notifications
You must be signed in to change notification settings - Fork 30
feat(website): Deco Analytics collector, gated like its predecessor #1660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { Head } from "$fresh/runtime.ts"; | ||
|
|
||
| /** | ||
| * Deco Analytics — the first-party collector. | ||
| * | ||
| * Replaces `<OneDollarStats />`, and the difference that matters is not the vendor. It is | ||
| * WHERE THE LOGIC LIVES. | ||
| * | ||
| * OneDollarStats ships roughly sixty lines of tracking code inside the site bundle: the | ||
| * pushState patch, the flag reading, the event mapping, the truncation. Every one of those | ||
| * is a decision that can be wrong, and fixing any of them means redeploying every site | ||
| * that embeds it — across ~500 storefronts that is not a fix, it is a campaign. | ||
| * | ||
| * This component is a script tag and nothing else. The runtime, the commerce mapping, the | ||
| * deco adapter and the per-site module composition are all served from the edge and | ||
| * versioned there, so a correction ships with a cache purge instead of a fleet deploy. | ||
| * That is also why there is deliberately NO npm package: a package would put a copy of the | ||
| * runtime back inside every site bundle, which is the problem this shape exists to avoid. | ||
| * | ||
| * It also does not stringify money. OneDollarStats flattens every param through | ||
| * `JSON.stringify` into a 990-byte string prop, so a purchase value arrives as text and | ||
| * revenue cannot be summed without parsing it back. Ours lands in typed columns. | ||
| * | ||
| * NOTE ON NAMING: `analytics/loaders/DecoAnalyticsScript.ts` already exists in this repo | ||
| * and is a **Plausible** loader despite the name. This is unrelated to it. | ||
| */ | ||
| export interface Props { | ||
| /** | ||
| * Where the script is served from and where events are sent. | ||
| * | ||
| * EMPTY IS THE RIGHT ANSWER for a site behind our CDN: a relative path keeps the request | ||
| * first-party, which is not a detail — a first-party request is not blocked by tracking | ||
| * protection, and the `Host` header then identifies the site. `Host` cannot be forged, | ||
| * which is why it is the only source billing may trust. | ||
| */ | ||
| origin?: string; | ||
|
|
||
| /** | ||
| * Only for a site NOT served through our CDN. | ||
| * | ||
| * A declared key rides in a public script attribute, so anyone can read it and post with | ||
| * someone else's. Events carrying one are recorded as tag-sourced and are never used for | ||
| * billing — the key identifies, it does not authenticate. | ||
| */ | ||
| siteKey?: string; | ||
|
|
||
| /** | ||
| * Off by default. The script is already `async` and nothing renders from it, so deferring | ||
| * only delays the first pageview — which is the one event a realtime view needs. | ||
| */ | ||
| defer?: boolean; | ||
| } | ||
|
|
||
| export default function Stats({ origin = "", siteKey, defer }: Props) { | ||
| const src = `${origin}/_dq/a.js${siteKey ? `?k=${encodeURIComponent(siteKey)}` : ""}`; | ||
| return ( | ||
| <Head> | ||
| {/* Only when the collector is on another origin. Preconnecting to our own is noise. */} | ||
| {origin ? <link rel="preconnect" href={origin} /> : null} | ||
| {/* | ||
| `async`, and nothing on the page waits on it. A failure here has to degrade to | ||
| "analytics stopped", never to "the page broke" — no island awaits this and no | ||
| rendering path reads from it. | ||
| */} | ||
| <script async={!defer} defer={defer} src={src} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The default Prompt for AI agents |
||
| </Head> | ||
| ); | ||
| } | ||
|
Comment on lines
+55
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Run CI rejects this file because 🧰 Tools🪛 GitHub Actions: ci / 0_Bundle & Check Apps (ubuntu-latest).txt[error] 55-68: deno fmt --check failed: file is not formatted. Run 'deno fmt' to fix formatting. 🪛 GitHub Actions: ci / Bundle & Check Apps (ubuntu-latest)[error] 55-68: deno fmt --check reported this file as not formatted. Run 'deno fmt' to fix formatting. 🤖 Prompt for AI AgentsSource: Pipeline failures |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: This note points to
analytics/loaders/DecoAnalyticsScript.ts, but that file does not exist in this checkout, sending maintainers to a dead reference. Remove the note or replace it with the actual loader path.Prompt for AI agents