@nexly/web 0.15.3 → 0.16.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
@@ -19,7 +19,7 @@ const client = Nexly.init({
19
19
  })
20
20
 
21
21
  client.pageview()
22
- client.event({ name: 'cta_clicked', type: 'custom', data: { placement: 'hero' } })
22
+ client.customEvent('cta_clicked', { placement: 'hero' })
23
23
 
24
24
  const stopEngagement = client.startEngagement()
25
25
  // stopEngagement() on SPA unmount / route change if needed
@@ -32,7 +32,7 @@ const stopEngagement = client.startEngagement()
32
32
  Auto-click and auto-focus listeners skip any element (or descendant of an element) marked with `data-nexly-ignore`. Use it on elements where you already emit your own `event(...)` to avoid semantic duplicates:
33
33
 
34
34
  ```tsx
35
- <button data-nexly-ignore onClick={() => client.event({ name: 'signup_clicked', type: 'custom' })}>
35
+ <button data-nexly-ignore onClick={() => client.customEvent('signup_clicked')}>
36
36
  Sign up
37
37
  </button>
38
38
  ```
@@ -46,6 +46,32 @@ Auto-click and auto-focus listeners skip any element (or descendant of an elemen
46
46
 
47
47
  For React bindings use [`@nexly/react-web`](https://www.npmjs.com/package/@nexly/react-web); for Next.js App Router use [`@nexly/next`](https://www.npmjs.com/package/@nexly/next); for React Native use [`@nexly/react-native`](https://www.npmjs.com/package/@nexly/react-native); for Node.js servers use [`@nexly/node`](https://www.npmjs.com/package/@nexly/node).
48
48
 
49
+ ## Custom analytics events
50
+
51
+ For application-specific events use the ergonomic `customEvent` API. It takes three arguments and always emits an `event_type: 'custom'` event:
52
+
53
+ ```ts
54
+ client.customEvent('checkout_completed', {
55
+ plan_id: 'pro',
56
+ amount_cents: 4200,
57
+ items: 3,
58
+ })
59
+ ```
60
+
61
+ - **`name`** — registered as a custom analytics event in the dashboard. Unapproved names show up under Discovered for later approval and do not enter analytics until you accept them.
62
+ - **`cdata`** — user-defined custom properties. Values must be `string`, `number`, or `boolean`; numbers and booleans are normalised to strings server-side. Nested objects, arrays, and `null` are silently dropped.
63
+ - **`context`** *(optional)* — per-event attribution override for the standard marketing parameters (`utm_source`, `utm_medium`, `utm_campaign`, `utm_content`, `utm_term`, `gclid`, `gad_source`, `gad_campaignid`, `fbclid`, `msclkid`, `ttclid`, `li_fat_id`, `yclid`, `mc_cid`, `ref`). Useful when the landing URL no longer carries them at click time (single-page navigation, deep-links, post-redirect flows). Only standard attribution keys are accepted in this slot.
64
+
65
+ ```ts
66
+ client.customEvent(
67
+ 'signup_clicked',
68
+ { source_section: 'pricing' },
69
+ { utm_source: 'newsletter', utm_campaign: 'q2-launch' },
70
+ )
71
+ ```
72
+
73
+ The generic `client.event({ name, type, cdata, data, context })` remains available when you need to set Nexly-known context fields like `visitor_id` alongside custom properties.
74
+
49
75
  ## Linking backend events to this visitor
50
76
 
51
77
  If you also emit server-side events with [`@nexly/node`](https://www.npmjs.com/package/@nexly/node) and want them to show up on the same user timeline as browser activity, forward the browser's Nexly visitor id to your backend once (on sign-up / login), persist it next to your own user record, and pass it through in `context` when emitting backend events.
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /** Session-stable metadata: user agent, screen, language, timezone, etc. */
7
7
  export declare function collectSessionMeta(): Record<string, unknown>;
8
- /** Per-event volatile metadata: visitor/session IDs, current URL/pathname. */
8
+ /** Per-event volatile metadata: visitor/session IDs, current URL/path. */
9
9
  export declare function collectEventMeta(): Record<string, unknown>;
10
10
  /** Legacy: full browser metadata (session + event merged). */
11
11
  export declare function collectBrowserMeta(): Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"browser-meta.d.ts","sourceRoot":"","sources":["../src/browser-meta.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,4EAA4E;AAC5E,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4E5D;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgB1D;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE5D"}
1
+ {"version":3,"file":"browser-meta.d.ts","sourceRoot":"","sources":["../src/browser-meta.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,4EAA4E;AAC5E,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4E5D;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAe1D;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE5D"}
@@ -88,7 +88,7 @@ export function collectSessionMeta() {
88
88
  }
89
89
  return filterEmpty(out);
90
90
  }
91
- /** Per-event volatile metadata: visitor/session IDs, current URL/pathname. */
91
+ /** Per-event volatile metadata: visitor/session IDs, current URL/path. */
92
92
  export function collectEventMeta() {
93
93
  if (typeof window === 'undefined' || typeof navigator === 'undefined') {
94
94
  return {};
@@ -98,7 +98,6 @@ export function collectEventMeta() {
98
98
  out.session_id = safe(() => getSessionId());
99
99
  out.url = safe(() => window.location.href);
100
100
  const pathname = safe(() => window.location.pathname);
101
- out.pathname = pathname;
102
101
  // Engagement/lifecycle events dispatch directly via sendBeaconCollect and
103
102
  // bypass NexlyBase.dispatch (which adds `path` from getDefaultPath). Include
104
103
  // `path` here so every event carries it.
package/dist/index.d.ts CHANGED
@@ -7,6 +7,6 @@ export { collectBrowserMeta, collectSessionMeta, collectEventMeta } from './brow
7
7
  export { getSessionId, getVisitorId } from './session.js';
8
8
  export { sendBeaconCollect, type SendBeaconCollectInput } from './beacon.js';
9
9
  export { getDefaultPathname, sendPageViewBeacon, startEngagementTracking, startOutboundLinkTracking, } from './events/index.js';
10
- export type { CollectCredentials, IngestCredentials, TrackEventInput } from '@nexly/core';
10
+ export type { CData, CollectCredentials, IngestCredentials, StandardContextOverride, TrackEventInput, } from '@nexly/core';
11
11
  export { buildCollectPayload } from '@nexly/core';
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC5F,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAC5E,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC5F,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAC5E,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,KAAK,EACL,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,GAChB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexly/web",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "description": "Nexly browser ingest SDK: sendBeacon transport, DOM metadata, engagement listeners on top of @nexly/core",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -38,7 +38,7 @@
38
38
  "node": ">=20"
39
39
  },
40
40
  "dependencies": {
41
- "@nexly/core": "0.15.3"
41
+ "@nexly/core": "0.16.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "~6.0.2"