@traqio/web 0.3.2 → 0.4.1

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/build/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { type WebSource } from "./source";
2
+ import { type AnalyticsOptions } from "./analytics";
2
3
  export type { WebSource } from "./source";
4
+ export type { AnalyticsOptions } from "./analytics";
3
5
  export declare const DEFAULT_ENDPOINT = "https://api.traqio.app";
4
6
  export interface WebInitOptions {
5
7
  /** The site's WEB key (`tq_web_…`), from the console. Public by design: it is held to the site's origins. */
@@ -36,6 +38,13 @@ export interface WebInitOptions {
36
38
  * site, `false` to count a local page.
37
39
  */
38
40
  debug?: boolean;
41
+ /**
42
+ * Product analytics — page views (route changes included), clicks, scroll depth and
43
+ * front-end errors, read in the console's Analytics section. `true` turns all four
44
+ * on; an object picks. Default off. Never billed and never sent to an ad network:
45
+ * analytics events have their own route and table, apart from conversions.
46
+ */
47
+ analytics?: boolean | AnalyticsOptions;
39
48
  }
40
49
  /** What `track()` accepts beside the event name. */
41
50
  export interface WebTrackProps {
@@ -56,6 +65,12 @@ export declare class TraqioWeb {
56
65
  private started;
57
66
  /** A `setConsent()` made before `init()` — it decides whether init may store. */
58
67
  private earlyConsent;
68
+ private analytics;
69
+ private userId;
70
+ /** `capture()` calls made before `init()` finished — replayed once the tracker exists. */
71
+ private earlyCaptures;
72
+ /** `init()` has finished (or will never run here): early captures are no longer kept. */
73
+ private ready;
59
74
  /**
60
75
  * Call once, as early as possible on every page (or once in a single-page app).
61
76
  * Reads the trackID from the current URL first, synchronously, so even a visitor
@@ -67,6 +82,18 @@ export declare class TraqioWeb {
67
82
  get isDebug(): boolean;
68
83
  /** Record an event — `signup`, `purchase`, `add_to_cart`… Batched, retried, kept across page loads. */
69
84
  track(name: string, props?: WebTrackProps): void;
85
+ /**
86
+ * A product-analytics event — `search_performed`, `pricing_toggled`… — read in the
87
+ * console's Analytics section (events, funnels). NOT a conversion: it is never
88
+ * billed nor sent to an ad network. A conversion (sign-up, purchase) is `track()`.
89
+ * Needs `analytics` at init; names starting with `$` are reserved.
90
+ */
91
+ capture(name: string, props?: Record<string, unknown>): void;
92
+ /**
93
+ * Record a page view now. Not needed with the history API (route changes are
94
+ * caught by themselves); for a router that changes the page another way.
95
+ */
96
+ pageview(): void;
70
97
  /** Set the user id once known (after sign-in). */
71
98
  setUserId(id: string): void;
72
99
  /**