@meiroio/web-sdk 0.1.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 ADDED
@@ -0,0 +1,85 @@
1
+ # @meiroio/web-sdk
2
+
3
+ The browser SDK for collecting website events with Meiro Pipes. It packages the same runtime served by
4
+ `/mpt.js`, with a typed module API and configuration properties suitable for bundled web applications.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install @meiroio/web-sdk
10
+ ```
11
+
12
+ ## Quick start
13
+
14
+ ```ts
15
+ import { createMpt } from '@meiroio/web-sdk';
16
+
17
+ const mpt = createMpt({
18
+ collectionEndpoint: 'https://your-domain.com/collect/website',
19
+ crossDomainWhitelist: ['checkout.your-domain.com'],
20
+ linkTracking: { enabled: true },
21
+ consent: {
22
+ storagePersistence: 'granted',
23
+ userId: 'granted',
24
+ sessionId: 'granted',
25
+ },
26
+ });
27
+
28
+ await mpt.event('page_view');
29
+ ```
30
+
31
+ Create the client once per page. The package and the script-tag version share the same browser-global runtime model, so
32
+ do not load `/mpt.js` when the npm package is in use.
33
+
34
+ The package is safe to import from code that can run during server-side rendering, but call `createMpt` only in the
35
+ browser.
36
+
37
+ ## API
38
+
39
+ ### `createMpt(options)`
40
+
41
+ Creates or updates the page's singleton SDK client. Consent supplied during creation is applied before configuration so
42
+ identity storage respects the requested consent from the start.
43
+
44
+ The module API uses camelCase properties. Its configuration maps directly to the script-tag API:
45
+
46
+ | Module property | Script-tag property |
47
+ | ---------------------- | -------------------------- |
48
+ | `collectionEndpoint` | `collection_endpoint` |
49
+ | `crossDomainWhitelist` | `cross_domain_whitelist` |
50
+ | `linkTracking` | `link_tracking` |
51
+ | `idSync` | `id_sync` |
52
+ | `theTradeDesk` | `the_trade_desk` |
53
+ | `googlePixel` | `google_pixel` |
54
+ | `trackingRules` | `tracking_rules` |
55
+ | `webBanners` | `web_banners` |
56
+
57
+ ### Client methods
58
+
59
+ ```ts
60
+ mpt.config({ linkTracking: { enabled: false } });
61
+ mpt.consent({ userId: 'denied', sessionId: 'denied' });
62
+ mpt.set({ customerTier: 'premium' });
63
+
64
+ await mpt.event('purchase', {
65
+ transaction_id: 'order-123',
66
+ value: 49.9,
67
+ currency: 'USD',
68
+ });
69
+
70
+ const userId = mpt.get('userId');
71
+ const sessionId = mpt.get('sessionId');
72
+ ```
73
+
74
+ - `config(update)` deep-merges a configuration update into the active configuration.
75
+ - `consent(update)` updates consent choices.
76
+ - `set(payload)` replaces the shared payload attached to subsequent events.
77
+ - `event(name, payload?)` resolves after the event delivery attempt.
78
+ - `get('userId' | 'sessionId')` returns the current SDK-managed identifier.
79
+
80
+ ## Release
81
+
82
+ 1. Update `version` in `package.json`.
83
+ 2. Run `bun run typecheck`, `bun run test`, and `bun run build` from this directory.
84
+ 3. Inspect the package with `npm pack --dry-run`.
85
+ 4. Publish with `npm publish --access public`.
@@ -0,0 +1,7 @@
1
+ import type { MptClient, MptOptions } from './types.js';
2
+
3
+ export * from './types.js';
4
+
5
+ export declare function createMpt(options: MptOptions): MptClient;
6
+
7
+ export default createMpt;