@crelora/mark 0.2.2 → 0.3.0

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/README.md CHANGED
@@ -52,6 +52,7 @@ Mark.init({
52
52
  cross_domain: { cookie_domain: '.example.com' },
53
53
  site_id: 'uuid-...', // Optional: associate events with a registered site
54
54
  site_host: 'shop.example.com', // Optional: site host for audit/debug
55
+ visitor_id: 'platform_client_id', // Optional: adopt trusted first-party anonymous id when storage is empty
55
56
  autocapture: { pageview: true }, // Optional: auto-emit page_view on load and SPA route changes
56
57
  });
57
58
 
@@ -99,6 +100,7 @@ The Node factory accepts optional custom storage or transport adapters so you ca
99
100
  - `track(eventName, payload?)` – records custom events with arbitrary properties (numbers, strings, arrays, objects). Use `site_id` and `site_host` for per-event site overrides.
100
101
  - `conversion(eventName, payload?)` – records conversion events (same endpoint path as track, with `is_conversion: true` for backend compatibility).
101
102
  - `identify(userId, traits?)` – ties a known user identifier to previous anonymous activity. Recommended traits: `email`, `display_name`, `language`. Custom traits are also supported.
103
+ - `setVisitorId(visitorId)` – adopts or replaces the stored anonymous visitor id with a trusted first-party value (for example a platform client id). Updates storage and cookies immediately on the browser. Use when the id is available after init; theme embeds and pixels should use the same source id.
102
104
  - `setConsent(status)` – enforces consent gating; pass `'granted'` or `'denied'`.
103
105
  - `getVisitorId()` – returns the current pseudonymous visitor ID when available. On the browser, returns `undefined` until consent is granted when `require_consent` is set. Use it to send the ID to your backend (e.g. in a header or body) for server-side attribution when you don't have an authenticated user ID.
104
106
  - `flush()` – flushes queued/persisted delivery items.
@@ -162,6 +164,7 @@ All config options use snake_case. Stored event payloads and database columns ma
162
164
  | `cross_domain` | `CrossDomainConfig` | Controls cookie domain, bridge URL, and allowlist for multi-domain attribution. |
163
165
  | `site_id` | `string` | Optional UUID for associating events with a registered site. Included in all event payloads as `site_id`. |
164
166
  | `site_host` | `string` | Optional site host for audit/debug purposes. Included in all event payloads as `site_host`. If not provided, browser SDK uses `window.location.host`. |
167
+ | `visitor_id` | `string` | Optional trusted first-party anonymous id to adopt when no visitor id is stored yet (ignored if storage already has one). Use `setVisitorId()` when the id arrives after init. |
165
168
  | `capture_query_params` | `string[]` | Additional query keys to capture for attribution (merged into the default allowlist). |
166
169
  | `capture_all_query_params` | `boolean` | Capture all query params after denylist/limits. Defaults to `false`. |
167
170
  | `query_param_denylist` | `string[]` | Query keys that are never captured (exact-key matching; default includes sensitive keys like `email`, `token`, `password`). |
@@ -194,7 +197,21 @@ When you don't have an authenticated user ID, you can pass the SDK's visitor ID
194
197
 
195
198
  **Browser:** Call `Mark.getVisitorId()` after init. If you use `require_consent: true` or `'auto'`, it returns `undefined` until consent is granted. Once available, send it in a header or request body to your API and use it as the `visitor_id` when calling the Node SDK or your ingestion.
196
199
 
197
- **Node:** Call `mark.getVisitorId()` to read the visitor ID from the storage you passed to `createNodeMark` (e.g. from `storageDefaults.visitor_id`). Use it to associate server events with the same visitor.
200
+ **Adopting an external anonymous id:** When your platform already provides a stable first-party anonymous key (for example a Shopify client id), pass it at init or call `Mark.setVisitorId()` once it is available:
201
+
202
+ ```ts
203
+ Mark.init({
204
+ key: 'pk_xxxxx',
205
+ visitor_id: platformClientId, // only adopted when storage is empty
206
+ });
207
+
208
+ // Or when the id arrives asynchronously:
209
+ Mark.setVisitorId(platformClientId);
210
+ ```
211
+
212
+ Use this for trusted first-party ids only — not email addresses, order ids, or values from unvalidated URL parameters. `identify()` sets `user_id` (known person), not `visitor_id` (anonymous device/browser key). After `Mark.reset()`, the SDK rotates to a fresh generated visitor id.
213
+
214
+ **Node:** Call `mark.getVisitorId()` to read the visitor ID from the storage you passed to `createNodeMark` (e.g. from `storageDefaults.visitor_id` or `Mark.init`-equivalent config `visitor_id`). Use `mark.setVisitorId()` to update the id for the current server-side client instance.
198
215
 
199
216
  The visitor ID is a pseudonymous, SDK-scoped identifier. Do not use it as a cross-site or long-term user identity; use it only for joining browser and server events within your attribution flow.
200
217