@vibiz/app 0.3.24 → 0.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -174,7 +174,49 @@ export interface CheckoutInput {
174
174
  metadata?: Record<string, string>;
175
175
  /** Your business's look on the checkout page, over the project's brand field by field. */
176
176
  brand?: CheckoutBrand;
177
+ /**
178
+ * Where the buyer came from: pass what `attribution()` returned in their
179
+ * browser (send it to your server with the checkout request). Kept on the
180
+ * payment, so you can see which source brings sales.
181
+ */
182
+ attribution?: Attribution | null;
183
+ }
184
+ /**
185
+ * First-touch attribution of one browser tab, kept by the analytics tag in
186
+ * `sessionStorage` (no cookies, gone when the tab closes): where the visit came
187
+ * from, the page it landed on, the page asking now, and the analytics
188
+ * visitor-day that links a sale to the visitor's path.
189
+ */
190
+ export interface Attribution {
191
+ /** Referrer host or `utm_source`; null: a direct visit. */
192
+ source: string | null;
193
+ referrer: string | null;
194
+ utm_source: string | null;
195
+ utm_medium: string | null;
196
+ utm_campaign: string | null;
197
+ utm_term: string | null;
198
+ utm_content: string | null;
199
+ landing_page: string | null;
200
+ /** The page `attribution()` was called on: where the checkout started. */
201
+ checkout_page: string | null;
202
+ /** The analytics visitor-day (GET /v1/projects/:id/analytics/visitors/:visitor_id?day=). */
203
+ visitor_id: string | null;
204
+ day: string | null;
205
+ first_seen_at: string | null;
177
206
  }
207
+ /**
208
+ * In the browser: this tab's first-touch attribution from the analytics tag,
209
+ * or null (on the server, before the tag has loaded, or without the tag).
210
+ * Needs no key. Put it in your checkout request, then pass it as
211
+ * `attribution` to `vibiz.payments.checkout`, or flatten it into your own
212
+ * processor's metadata:
213
+ *
214
+ * const a = attribution();
215
+ * const metadata = Object.fromEntries(
216
+ * Object.entries(a ?? {}).filter(([, v]) => v).map(([k, v]) => [`vz_${k}`, String(v)]),
217
+ * );
218
+ */
219
+ export declare function attribution(): Attribution | null;
178
220
  /**
179
221
  * How the hosted checkout page looks. Left out, a field comes from the
180
222
  * project's brand (console ▸ Payments, or `PATCH …/payments { brand }`).
@@ -835,6 +877,13 @@ export declare class VibizApp {
835
877
  };
836
878
  }) => Promise<WebhookEvent<T>>;
837
879
  };
880
+ /**
881
+ * Analytics helpers. `attribution()` runs in the browser (no key, no
882
+ * request): the tab's first-touch attribution, to send with a checkout.
883
+ */
884
+ readonly analytics: {
885
+ attribution: typeof attribution;
886
+ };
838
887
  /**
839
888
  * A server-side event in the project's analytics, next to the browser's.
840
889
  * Never throws: analytics must not break the request that tracks it.
package/dist/index.js CHANGED
@@ -13,6 +13,20 @@ var VibizAppError = class extends Error {
13
13
  this.details = details;
14
14
  }
15
15
  };
16
+ function attribution() {
17
+ const w = globalThis.window;
18
+ try {
19
+ const got = w?.vibiz?.attribution?.();
20
+ if (got && typeof got === "object") return got;
21
+ const raw = globalThis.sessionStorage?.getItem("_vz_a");
22
+ if (!w || !raw) return null;
23
+ const a = JSON.parse(raw);
24
+ const page = globalThis.location?.pathname;
25
+ return { ...a, checkout_page: page ?? a.checkout_page ?? null };
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
16
30
  var WEBHOOK_TOLERANCE_S = 300;
17
31
  var K = new Uint32Array([
18
32
  1116352408,
@@ -591,6 +605,11 @@ var VibizApp = class _VibizApp {
591
605
  }
592
606
  }
593
607
  };
608
+ /**
609
+ * Analytics helpers. `attribution()` runs in the browser (no key, no
610
+ * request): the tab's first-touch attribution, to send with a checkout.
611
+ */
612
+ analytics = { attribution };
594
613
  /**
595
614
  * A server-side event in the project's analytics, next to the browser's.
596
615
  * Never throws: analytics must not break the request that tracks it.
@@ -621,6 +640,7 @@ var vibiz = new VibizApp();
621
640
  export {
622
641
  VibizApp,
623
642
  VibizAppError,
643
+ attribution,
624
644
  createVibiz,
625
645
  verifyWebhook,
626
646
  vibiz
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibiz/app",
3
- "version": "0.3.24",
3
+ "version": "0.3.25",
4
4
  "description": "One key for your app: env, AI, email, actions and events from thelastapi.",
5
5
  "keywords": [
6
6
  "vibiz",