@nexly/core 0.5.0 → 0.7.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 +10 -0
- package/dist/events/engagement.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/nexly.d.ts +11 -1
- package/dist/nexly.d.ts.map +1 -1
- package/dist/nexly.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,16 @@ nexly.event({ name: 'click', type: 'engagement', data: { id: 'x' } })
|
|
|
23
23
|
|
|
24
24
|
Constructor options use the `NexlyInit` type from the published typings.
|
|
25
25
|
|
|
26
|
+
### Singleton
|
|
27
|
+
|
|
28
|
+
When using a provider (`@nexly/react-web` or `@nexly/next`), the client is also available as a singleton — useful for plain functions outside the React tree:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { Nexly } from '@nexly/core'
|
|
32
|
+
|
|
33
|
+
Nexly.getInstance()?.event({ name: 'click', type: 'engagement' })
|
|
34
|
+
```
|
|
35
|
+
|
|
26
36
|
## API
|
|
27
37
|
|
|
28
38
|
The package ships `.d.ts` files; use your editor or `node_modules` typings for the full export list.
|
|
@@ -103,7 +103,7 @@ export function startEngagementTracking(creds) {
|
|
|
103
103
|
flushScrollDepth();
|
|
104
104
|
const secs = Math.round(accumulatedVisibleMs / 1000);
|
|
105
105
|
if (secs > 0) {
|
|
106
|
-
sendEngagement(creds, 'visibility_change', '
|
|
106
|
+
sendEngagement(creds, 'visibility_change', 'engagement', { visible_seconds: secs, state: 'hidden' });
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
else {
|
|
@@ -118,7 +118,7 @@ export function startEngagementTracking(creds) {
|
|
|
118
118
|
}
|
|
119
119
|
flushScrollDepth();
|
|
120
120
|
const secs = Math.round(accumulatedVisibleMs / 1000);
|
|
121
|
-
sendEngagement(creds, 'visibility_change', '
|
|
121
|
+
sendEngagement(creds, 'visibility_change', 'engagement', { visible_seconds: secs, state: 'unload' });
|
|
122
122
|
}
|
|
123
123
|
window.addEventListener('beforeunload', onBeforeUnload, { signal });
|
|
124
124
|
// ---- heartbeat ----
|
|
@@ -127,7 +127,7 @@ export function startEngagementTracking(creds) {
|
|
|
127
127
|
if (document.visibilityState !== 'visible')
|
|
128
128
|
return;
|
|
129
129
|
const elapsed = Math.round((Date.now() - startTime) / 1000);
|
|
130
|
-
sendEngagement(creds, 'heartbeat', '
|
|
130
|
+
sendEngagement(creds, 'heartbeat', 'engagement', { elapsed_seconds: elapsed });
|
|
131
131
|
}
|
|
132
132
|
const heartbeatId = setInterval(sendHeartbeat, HEARTBEAT_INTERVAL_MS);
|
|
133
133
|
// ---- cleanup ----
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Browser event ingest client (public API).
|
|
3
3
|
*/
|
|
4
|
-
export { Nexly, type NexlyEventInput, type NexlyInit } from './nexly.js';
|
|
4
|
+
export { Nexly, type NexlyEventInput, type NexlyEventType, type NexlyInit } from './nexly.js';
|
|
5
5
|
export { collectBrowserMeta } from './browser-meta.js';
|
|
6
6
|
export { getSessionId, getVisitorId } from './session.js';
|
|
7
7
|
export { buildCollectPayload, sendBeaconCollect, type CollectCredentials, type IngestCredentials, type SendBeaconCollectInput, type TrackEventInput, } from './collect.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAA;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/nexly.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export type NexlyInit = {
|
|
|
5
5
|
appId: string;
|
|
6
6
|
key: string;
|
|
7
7
|
};
|
|
8
|
+
/** Allowed event types. The backend rejects any other value. */
|
|
9
|
+
export type NexlyEventType = 'pageview' | 'engagement' | 'custom';
|
|
8
10
|
export type NexlyEventInput = {
|
|
9
11
|
name: string;
|
|
10
|
-
type:
|
|
12
|
+
type: NexlyEventType;
|
|
11
13
|
data?: Record<string, unknown>;
|
|
12
14
|
/** Merged on top of default browser context (see {@link collectBrowserMeta}) and current `path`. */
|
|
13
15
|
context?: Record<string, unknown>;
|
|
@@ -16,6 +18,14 @@ export type NexlyEventInput = {
|
|
|
16
18
|
* High-level browser client: page views, custom events, optional engagement auto-tracking.
|
|
17
19
|
*/
|
|
18
20
|
export declare class Nexly {
|
|
21
|
+
private static instance;
|
|
22
|
+
/**
|
|
23
|
+
* Creates (or replaces) the global singleton and returns it.
|
|
24
|
+
* The provider calls this; plain functions use {@link getInstance}.
|
|
25
|
+
*/
|
|
26
|
+
static init(options: NexlyInit): Nexly;
|
|
27
|
+
/** Returns the singleton created by {@link init}, or `null` if not yet initialized. */
|
|
28
|
+
static getInstance(): Nexly | null;
|
|
19
29
|
readonly collectUrl: string;
|
|
20
30
|
readonly appId: string;
|
|
21
31
|
readonly key: string;
|
package/dist/nexly.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nexly.d.ts","sourceRoot":"","sources":["../src/nexly.ts"],"names":[],"mappings":"AAMA,kGAAkG;AAClG,MAAM,MAAM,SAAS,GAAG;IACtB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"nexly.d.ts","sourceRoot":"","sources":["../src/nexly.ts"],"names":[],"mappings":"AAMA,kGAAkG;AAClG,MAAM,MAAM,SAAS,GAAG;IACtB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,gEAAgE;AAChE,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAA;AAEjE,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,cAAc,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,oGAAoG;IACpG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC,CAAA;AAED;;GAEG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;IAE5C;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,KAAK;IAKtC,uFAAuF;IACvF,MAAM,CAAC,WAAW,IAAI,KAAK,GAAG,IAAI;IAIlC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;gBAER,IAAI,EAAE,SAAS;IAM3B,OAAO,KAAK,WAAW,GAMtB;IAED,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IAIhC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO;IActC;;OAEG;IACH,eAAe,IAAI,MAAM,IAAI;CAG9B"}
|
package/dist/nexly.js
CHANGED
|
@@ -6,6 +6,19 @@ const DEFAULT_COLLECT_URL = 'https://gate.nexly.to/v1/collect';
|
|
|
6
6
|
* High-level browser client: page views, custom events, optional engagement auto-tracking.
|
|
7
7
|
*/
|
|
8
8
|
export class Nexly {
|
|
9
|
+
static instance = null;
|
|
10
|
+
/**
|
|
11
|
+
* Creates (or replaces) the global singleton and returns it.
|
|
12
|
+
* The provider calls this; plain functions use {@link getInstance}.
|
|
13
|
+
*/
|
|
14
|
+
static init(options) {
|
|
15
|
+
Nexly.instance = new Nexly(options);
|
|
16
|
+
return Nexly.instance;
|
|
17
|
+
}
|
|
18
|
+
/** Returns the singleton created by {@link init}, or `null` if not yet initialized. */
|
|
19
|
+
static getInstance() {
|
|
20
|
+
return Nexly.instance;
|
|
21
|
+
}
|
|
9
22
|
collectUrl;
|
|
10
23
|
appId;
|
|
11
24
|
key;
|