@amplitude/amp-semantic 0.3.0 → 0.4.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 +19 -5
- package/lib/cjs/index.d.ts +3 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +5 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/recorders/visibility.d.ts +4 -0
- package/lib/cjs/recorders/visibility.d.ts.map +1 -0
- package/lib/cjs/recorders/visibility.js +22 -0
- package/lib/cjs/recorders/visibility.js.map +1 -0
- package/lib/cjs/types.d.ts +3 -0
- package/lib/cjs/types.d.ts.map +1 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/index.d.ts +3 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +4 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/recorders/visibility.d.ts +4 -0
- package/lib/esm/recorders/visibility.d.ts.map +1 -0
- package/lib/esm/recorders/visibility.js +19 -0
- package/lib/esm/recorders/visibility.js.map +1 -0
- package/lib/esm/types.d.ts +3 -0
- package/lib/esm/types.d.ts.map +1 -1
- package/lib/esm/types.js.map +1 -1
- package/package.json +5 -4
- package/schema.json +56 -0
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @amplitude/amp-semantic
|
|
2
2
|
|
|
3
|
-
Internal, composable semantic capture runtime for Amplitude.
|
|
3
|
+
Internal, composable semantic capture runtime for Amplitude. Context and visibility capture use a host interface. Session Replay supplies configuration, identity, lifecycle signals, and rrweb transport.
|
|
4
4
|
|
|
5
|
-
The host supplies a document, window, and transport callback. `createCapture` accepts typed recorder factories and optional per-family budgets (200 events per session by default). With
|
|
5
|
+
The host supplies a document, window, and transport callback. `createCapture` accepts typed recorder factories and optional per-family budgets (200 events per session by default). With an empty recorder list it emits nothing and installs no browser listeners.
|
|
6
6
|
|
|
7
7
|
The runtime owns opt-in sampling, start/stop and session reset, event version/timestamp/identity stamping, host snapshot signals, exception isolation, and cleanup rollback. Sampling and caps survive stop/start and reset only for a new session. Identity is allocated lazily when an event is accepted; its fallback is document-scoped memory, with no storage access.
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ Recorders register teardown immediately with `onCleanup` when setup can fail. `c
|
|
|
10
10
|
|
|
11
11
|
The `snapshot` host signal describes an accepted full snapshot; the runtime does not subscribe to rrweb itself. The host remains responsible for privacy-safe payloads, recording consent, transport, and any persisted tab identity.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Context and visibility are the only default recorders in this increment. Session Replay accepts this package through a locally supplied createCapture callback; capture remains disabled by default.
|
|
14
14
|
|
|
15
15
|
## Development
|
|
16
16
|
|
|
@@ -18,8 +18,22 @@ From the repository root, install dependencies and build with Node 24, `pnpm ins
|
|
|
18
18
|
|
|
19
19
|
## Context recorder
|
|
20
20
|
|
|
21
|
-
`createSemanticCapture(config, host)` installs the context
|
|
21
|
+
`createSemanticCapture(config, host)` installs the context and visibility recorders by default. The host additionally supplies `sdk`, `getPrivacy`, and optional analytics context and stylesheet-inlining configuration. Call `notify('snapshot', undefined)` after an accepted full snapshot to emit context. Starting capture alone emits nothing.
|
|
22
22
|
|
|
23
23
|
`amp-semantic/context` records the effective mask level for the snapshot URL (including URL overrides), stylesheet counts, viewport, a device heuristic, language, user agent, visibility and focus snapshots, analytics SDK configuration, and dropped-event counts. The runtime stamps version, timestamp and document identity. It never captures input values or page text.
|
|
24
24
|
|
|
25
|
-
The context budget is 200 events per session. At capacity the recorder skips stylesheet and other payload reads. Successfully delivered context acknowledges dropped-event diagnostics; failed delivery preserves them. `schema.json` describes the rrweb custom-event envelope
|
|
25
|
+
The context budget is 200 events per session. At capacity the recorder skips stylesheet and other payload reads. Successfully delivered context acknowledges dropped-event diagnostics; failed delivery preserves them. `schema.json` describes the rrweb custom-event envelope used by the Session Replay adapter.
|
|
26
|
+
|
|
27
|
+
## Session Replay integration
|
|
28
|
+
|
|
29
|
+
Import `createSemanticCapture` from `@amplitude/amp-semantic` and enable with `semanticCapture: { enabled: true, createCapture: createSemanticCapture }` (also supported by the Session Replay analytics plugin). Without a local createCapture callback, semantic capture is inert even if remote configuration enables it. The replay SDK has no production dependency on this package; applications that opt in include its code in their own bundle. To load it later, dynamically import the semantic package before initializing replay with its createCapture callback. Additional sampling and a per-family switch apply within replay-selected sessions. Remote configuration can disable capture. The adapter waits for rrweb readiness, forwards accepted full snapshots, and tears down capture on stop or reinitialization. A new session resets sampling and caps.
|
|
30
|
+
|
|
31
|
+
Accepted context becomes a type-5 rrweb custom event tagged `amp-semantic/context`. The host persists tab identity in session storage when available and keeps document identity in memory, with a fallback when storage is unavailable. The analytics plugin forwards its autocapture configuration.
|
|
32
|
+
|
|
33
|
+
For local validation, build with `pnpm build`, then run `pnpm exec vite --host 127.0.0.1 --port 5174 --strictPort`. Open `/session-replay-browser/sr-semantic-test.html`. The inspector uses local transport and no real API key. `pnpm --filter @amplitude/amp-semantic test:playwright` runs Chromium transport and lifecycle tests.
|
|
34
|
+
|
|
35
|
+
## Visibility recorder
|
|
36
|
+
|
|
37
|
+
`amp-semantic/visibility` emits only hidden/visible transitions, deduplicated from the document's `visibilitychange` event. Its payload contains `state`, version and identity; focus/blur alone do not emit events. The listener is removed on stop and recreated on resume. Disable only this family with `semanticCapture: { enabled: true, createCapture: createSemanticCapture, families: { visibility: false } }`.
|
|
38
|
+
|
|
39
|
+
The initial state is present in context. The visibility budget is 200 events per session. Native notification timing is browser-dependent; an embedded browser can report transitions late. Browser tests inject deterministic transitions to verify transport and timestamps, while native tab behavior should be checked manually in Chrome.
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { visibilityRecorder } from './recorders/visibility';
|
|
1
2
|
import { contextRecorder } from './recorders/context';
|
|
2
3
|
import type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';
|
|
3
4
|
export { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
4
|
-
export { contextRecorder };
|
|
5
|
+
export { contextRecorder, visibilityRecorder };
|
|
5
6
|
export declare const defaultRecorders: readonly SemanticRecorder[];
|
|
6
7
|
export declare const SEMANTIC_CAPS: {
|
|
7
8
|
context: number;
|
|
9
|
+
visibility: number;
|
|
8
10
|
};
|
|
9
11
|
export * from './types';
|
|
10
12
|
export type { SemanticCapture } from './capture';
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AAC/C,eAAO,MAAM,gBAAgB,EAAE,SAAS,gBAAgB,EAA0C,CAAC;AACnG,eAAO,MAAM,aAAa;;;CAAsE,CAAC;AACjG,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,YAAY,EAClB,SAAS,GAAE,SAAS,gBAAgB,EAAqB,2EAG1D"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSemanticCapture = exports.getDocumentIdentity = exports.SEMANTIC_CAPS = exports.defaultRecorders = exports.contextRecorder = exports.DEFAULT_SEMANTIC_CAP = exports.createCapture = void 0;
|
|
3
|
+
exports.createSemanticCapture = exports.getDocumentIdentity = exports.SEMANTIC_CAPS = exports.defaultRecorders = exports.visibilityRecorder = exports.contextRecorder = exports.DEFAULT_SEMANTIC_CAP = exports.createCapture = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var capture_1 = require("./capture");
|
|
6
|
+
var visibility_1 = require("./recorders/visibility");
|
|
7
|
+
Object.defineProperty(exports, "visibilityRecorder", { enumerable: true, get: function () { return visibility_1.visibilityRecorder; } });
|
|
6
8
|
var context_1 = require("./recorders/context");
|
|
7
9
|
Object.defineProperty(exports, "contextRecorder", { enumerable: true, get: function () { return context_1.contextRecorder; } });
|
|
8
10
|
var capture_2 = require("./capture");
|
|
9
11
|
Object.defineProperty(exports, "createCapture", { enumerable: true, get: function () { return capture_2.createCapture; } });
|
|
10
12
|
Object.defineProperty(exports, "DEFAULT_SEMANTIC_CAP", { enumerable: true, get: function () { return capture_2.DEFAULT_SEMANTIC_CAP; } });
|
|
11
|
-
exports.defaultRecorders = [context_1.contextRecorder];
|
|
12
|
-
exports.SEMANTIC_CAPS = { context: capture_1.DEFAULT_SEMANTIC_CAP };
|
|
13
|
+
exports.defaultRecorders = [context_1.contextRecorder, visibility_1.visibilityRecorder];
|
|
14
|
+
exports.SEMANTIC_CAPS = { context: capture_1.DEFAULT_SEMANTIC_CAP, visibility: capture_1.DEFAULT_SEMANTIC_CAP };
|
|
13
15
|
tslib_1.__exportStar(require("./types"), exports);
|
|
14
16
|
var identity_1 = require("./identity");
|
|
15
17
|
Object.defineProperty(exports, "getDocumentIdentity", { enumerable: true, get: function () { return identity_1.getDocumentIdentity; } });
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAgE;AAChE,+CAAsD;AAI7C,gGAJA,yBAAe,OAIA;AADxB,qCAAgE;AAAvD,wGAAA,aAAa,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAE/B,QAAA,gBAAgB,GAAgC,CAAC,yBAAe,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAgE;AAChE,qDAA4D;AAKlC,mGALjB,+BAAkB,OAKiB;AAJ5C,+CAAsD;AAI7C,gGAJA,yBAAe,OAIA;AADxB,qCAAgE;AAAvD,wGAAA,aAAa,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAE/B,QAAA,gBAAgB,GAAgC,CAAC,yBAAe,EAAE,+BAAkB,CAAC,CAAC;AACtF,QAAA,aAAa,GAAG,EAAE,OAAO,EAAE,8BAAoB,EAAE,UAAU,EAAE,8BAAoB,EAAE,CAAC;AACjG,kDAAwB;AAExB,uCAAiD;AAAxC,+GAAA,mBAAmB,OAAA;AAE5B,SAAgB,qBAAqB,CACnC,MAA6B,EAC7B,IAAkB,EAClB,SAAyD;IAAzD,0BAAA,EAAA,YAAyC,wBAAgB;IAEzD,OAAO,IAAA,uBAAa,EAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,qBAAa,CAAC,CAAC;AAC/D,CAAC;AAND,sDAMC","sourcesContent":["import { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nimport { visibilityRecorder } from './recorders/visibility';\nimport { contextRecorder } from './recorders/context';\nimport type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';\n\nexport { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nexport { contextRecorder, visibilityRecorder };\nexport const defaultRecorders: readonly SemanticRecorder[] = [contextRecorder, visibilityRecorder];\nexport const SEMANTIC_CAPS = { context: DEFAULT_SEMANTIC_CAP, visibility: DEFAULT_SEMANTIC_CAP };\nexport * from './types';\nexport type { SemanticCapture } from './capture';\nexport { getDocumentIdentity } from './identity';\n\nexport function createSemanticCapture(\n config: SemanticCaptureConfig,\n host: SemanticHost,\n recorders: readonly SemanticRecorder[] = defaultRecorders,\n) {\n return createCapture(config, host, recorders, SEMANTIC_CAPS);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../../src/recorders/visibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,EAAE,gBAehC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.visibilityRecorder = void 0;
|
|
4
|
+
/** Document visibility is independent of keyboard focus. */
|
|
5
|
+
exports.visibilityRecorder = {
|
|
6
|
+
families: ['visibility'],
|
|
7
|
+
setup: function (context) {
|
|
8
|
+
var document = context.host.document;
|
|
9
|
+
var readState = function () { return (document.visibilityState === 'hidden' ? 'hidden' : 'visible'); };
|
|
10
|
+
var previous = readState();
|
|
11
|
+
var onVisibility = function () {
|
|
12
|
+
var state = readState();
|
|
13
|
+
if (state === previous)
|
|
14
|
+
return;
|
|
15
|
+
previous = state;
|
|
16
|
+
context.emit('visibility', { state: state });
|
|
17
|
+
};
|
|
18
|
+
document.addEventListener('visibilitychange', onVisibility, true);
|
|
19
|
+
return function () { return document.removeEventListener('visibilitychange', onVisibility, true); };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=visibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.js","sourceRoot":"","sources":["../../../src/recorders/visibility.ts"],"names":[],"mappings":";;;AAEA,4DAA4D;AAC/C,QAAA,kBAAkB,GAAqB;IAClD,QAAQ,EAAE,CAAC,YAAY,CAAC;IACxB,KAAK,YAAC,OAAO;QACH,IAAA,QAAQ,GAAK,OAAO,CAAC,IAAI,SAAjB,CAAkB;QAClC,IAAM,SAAS,GAAG,cAAM,OAAA,CAAC,QAAQ,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,EAA9D,CAA8D,CAAC;QACvF,IAAI,QAAQ,GAAG,SAAS,EAAE,CAAC;QAC3B,IAAM,YAAY,GAAG;YACnB,IAAM,KAAK,GAAG,SAAS,EAAE,CAAC;YAC1B,IAAI,KAAK,KAAK,QAAQ;gBAAE,OAAO;YAC/B,QAAQ,GAAG,KAAK,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;QAClE,OAAO,cAAM,OAAA,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,YAAY,EAAE,IAAI,CAAC,EAApE,CAAoE,CAAC;IACpF,CAAC;CACF,CAAC","sourcesContent":["import type { SemanticRecorder } from '../types';\n\n/** Document visibility is independent of keyboard focus. */\nexport const visibilityRecorder: SemanticRecorder = {\n families: ['visibility'],\n setup(context) {\n const { document } = context.host;\n const readState = () => (document.visibilityState === 'hidden' ? 'hidden' : 'visible');\n let previous = readState();\n const onVisibility = () => {\n const state = readState();\n if (state === previous) return;\n previous = state;\n context.emit('visibility', { state });\n };\n document.addEventListener('visibilitychange', onVisibility, true);\n return () => document.removeEventListener('visibilitychange', onVisibility, true);\n },\n};\n"]}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -18,6 +18,9 @@ export interface SemanticEventEnvelope<Name extends string, Payload extends obje
|
|
|
18
18
|
}
|
|
19
19
|
/** Payloads exclude version and identity, which are owned by the runtime. */
|
|
20
20
|
export interface SemanticPayloads {
|
|
21
|
+
visibility: {
|
|
22
|
+
state: 'hidden' | 'visible';
|
|
23
|
+
};
|
|
21
24
|
context: {
|
|
22
25
|
sdk: string;
|
|
23
26
|
mask: 'light' | 'medium' | 'conservative';
|
package/lib/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3E,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AACD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AACD,oFAAoF;AACpF,MAAM,WAAW,qBAAqB,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM;IAChF,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,GAAG,gBAAgB,GAAG;QAAE,CAAC,EAAE,OAAO,gBAAgB,CAAA;KAAE,CAAC;CACtE;AAED,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE;QACP,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC;QAC1C,GAAG,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,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,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC;IACnG,yFAAyF;IACzF,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1D,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AACD,yEAAyE;AACzE,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,gBAAgB;IACnE,QAAQ,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,KAAK,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;CACjD"}
|
package/lib/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';\n\nexport const SEMANTIC_VERSION = 1;\nexport interface AnalyticsContext {\n present: boolean;\n autocapture: string[];\n}\nexport interface SemanticIdentity {\n readonly tab_id: string;\n readonly document_id: string;\n}\n/** Internal event envelope, independent of any event family or replay transport. */\nexport interface SemanticEventEnvelope<Name extends string, Payload extends object> {\n name: Name;\n timestamp: number;\n payload: Payload & SemanticIdentity & { v: typeof SEMANTIC_VERSION };\n}\n\n/** Payloads exclude version and identity, which are owned by the runtime. */\nexport interface SemanticPayloads {\n context: {\n sdk: string;\n mask: 'light' | 'medium' | 'conservative';\n css: { total: number; inlined: number; unreadable: number };\n viewport: { w: number; h: number };\n device: 'desktop' | 'tablet' | 'mobile';\n language: string;\n visibility_state: 'hidden' | 'visible';\n focused: boolean;\n user_agent: string;\n analytics_sdk: AnalyticsContext;\n caps_hit?: Partial<Record<SemanticFamily, number>>;\n };\n}\nexport type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;\nexport type SemanticEvent<P extends object = SemanticPayloads> = {\n [K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;\n}[SemanticFamily<P>];\nexport interface SemanticCaptureConfig<P extends object = SemanticPayloads> {\n enabled: boolean;\n /** Additional sampling within recorded replay sessions. Defaults to 1. */\n sampleRate?: number;\n /** Registered families are enabled unless explicitly false. */\n families?: Partial<Record<SemanticFamily<P>, boolean>>;\n}\nexport interface HostSignals {\n /** An accepted full snapshot, forwarded after the recorder is ready. */\n snapshot: undefined;\n}\nexport type Cleanup = () => void;\n/** The host owns transport; the runtime has no rrweb dependency. */\nexport interface SemanticHost<P extends object = SemanticPayloads> {\n document: Document;\n window: Window;\n sdk: string;\n getPrivacy: () => PrivacyConfig;\n getAnalyticsContext?: () => AnalyticsContext;\n inlineStylesheet?: boolean;\n emit: (event: SemanticEvent<P>) => void;\n /** Called lazily for accepted events. Defaults to document-scoped memory only. */\n getIdentity?: () => SemanticIdentity;\n now?: () => number;\n random?: () => number;\n onError?: (error: unknown) => void;\n}\nexport interface RecorderContext<P extends object = SemanticPayloads> {\n /** Register resources immediately so failed setup can roll them back. */\n onCleanup: (cleanup: Cleanup) => void;\n host: SemanticHost<P>;\n now: () => number;\n /** Check before expensive payload work. A rejected candidate increments the dropped count. */\n canEmit: (family: SemanticFamily<P>) => boolean;\n emit: <K extends SemanticFamily<P>>(family: K, payload: P[K], timestamp?: number) => boolean;\n on: <K extends keyof HostSignals>(signal: K, callback: (value: HostSignals[K]) => void) => Cleanup;\n /** Peek at dropped counts; a recorder can acknowledge them after successful delivery. */\n dropped: () => Partial<Record<SemanticFamily<P>, number>>;\n clearDropped: () => void;\n}\n/** A factory owns its listeners/timers and returns complete teardown. */\nexport interface SemanticRecorder<P extends object = SemanticPayloads> {\n families: readonly SemanticFamily<P>[];\n setup: (context: RecorderContext<P>) => Cleanup;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';\n\nexport const SEMANTIC_VERSION = 1;\nexport interface AnalyticsContext {\n present: boolean;\n autocapture: string[];\n}\nexport interface SemanticIdentity {\n readonly tab_id: string;\n readonly document_id: string;\n}\n/** Internal event envelope, independent of any event family or replay transport. */\nexport interface SemanticEventEnvelope<Name extends string, Payload extends object> {\n name: Name;\n timestamp: number;\n payload: Payload & SemanticIdentity & { v: typeof SEMANTIC_VERSION };\n}\n\n/** Payloads exclude version and identity, which are owned by the runtime. */\nexport interface SemanticPayloads {\n visibility: { state: 'hidden' | 'visible' };\n context: {\n sdk: string;\n mask: 'light' | 'medium' | 'conservative';\n css: { total: number; inlined: number; unreadable: number };\n viewport: { w: number; h: number };\n device: 'desktop' | 'tablet' | 'mobile';\n language: string;\n visibility_state: 'hidden' | 'visible';\n focused: boolean;\n user_agent: string;\n analytics_sdk: AnalyticsContext;\n caps_hit?: Partial<Record<SemanticFamily, number>>;\n };\n}\nexport type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;\nexport type SemanticEvent<P extends object = SemanticPayloads> = {\n [K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;\n}[SemanticFamily<P>];\nexport interface SemanticCaptureConfig<P extends object = SemanticPayloads> {\n enabled: boolean;\n /** Additional sampling within recorded replay sessions. Defaults to 1. */\n sampleRate?: number;\n /** Registered families are enabled unless explicitly false. */\n families?: Partial<Record<SemanticFamily<P>, boolean>>;\n}\nexport interface HostSignals {\n /** An accepted full snapshot, forwarded after the recorder is ready. */\n snapshot: undefined;\n}\nexport type Cleanup = () => void;\n/** The host owns transport; the runtime has no rrweb dependency. */\nexport interface SemanticHost<P extends object = SemanticPayloads> {\n document: Document;\n window: Window;\n sdk: string;\n getPrivacy: () => PrivacyConfig;\n getAnalyticsContext?: () => AnalyticsContext;\n inlineStylesheet?: boolean;\n emit: (event: SemanticEvent<P>) => void;\n /** Called lazily for accepted events. Defaults to document-scoped memory only. */\n getIdentity?: () => SemanticIdentity;\n now?: () => number;\n random?: () => number;\n onError?: (error: unknown) => void;\n}\nexport interface RecorderContext<P extends object = SemanticPayloads> {\n /** Register resources immediately so failed setup can roll them back. */\n onCleanup: (cleanup: Cleanup) => void;\n host: SemanticHost<P>;\n now: () => number;\n /** Check before expensive payload work. A rejected candidate increments the dropped count. */\n canEmit: (family: SemanticFamily<P>) => boolean;\n emit: <K extends SemanticFamily<P>>(family: K, payload: P[K], timestamp?: number) => boolean;\n on: <K extends keyof HostSignals>(signal: K, callback: (value: HostSignals[K]) => void) => Cleanup;\n /** Peek at dropped counts; a recorder can acknowledge them after successful delivery. */\n dropped: () => Partial<Record<SemanticFamily<P>, number>>;\n clearDropped: () => void;\n}\n/** A factory owns its listeners/timers and returns complete teardown. */\nexport interface SemanticRecorder<P extends object = SemanticPayloads> {\n families: readonly SemanticFamily<P>[];\n setup: (context: RecorderContext<P>) => Cleanup;\n}\n"]}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { visibilityRecorder } from './recorders/visibility';
|
|
1
2
|
import { contextRecorder } from './recorders/context';
|
|
2
3
|
import type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';
|
|
3
4
|
export { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
4
|
-
export { contextRecorder };
|
|
5
|
+
export { contextRecorder, visibilityRecorder };
|
|
5
6
|
export declare const defaultRecorders: readonly SemanticRecorder[];
|
|
6
7
|
export declare const SEMANTIC_CAPS: {
|
|
7
8
|
context: number;
|
|
9
|
+
visibility: number;
|
|
8
10
|
};
|
|
9
11
|
export * from './types';
|
|
10
12
|
export type { SemanticCapture } from './capture';
|
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AAC/C,eAAO,MAAM,gBAAgB,EAAE,SAAS,gBAAgB,EAA0C,CAAC;AACnG,eAAO,MAAM,aAAa;;;CAAsE,CAAC;AACjG,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,YAAY,EAClB,SAAS,GAAE,SAAS,gBAAgB,EAAqB,2EAG1D"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
2
|
+
import { visibilityRecorder } from './recorders/visibility';
|
|
2
3
|
import { contextRecorder } from './recorders/context';
|
|
3
4
|
export { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
4
|
-
export { contextRecorder };
|
|
5
|
-
export var defaultRecorders = [contextRecorder];
|
|
6
|
-
export var SEMANTIC_CAPS = { context: DEFAULT_SEMANTIC_CAP };
|
|
5
|
+
export { contextRecorder, visibilityRecorder };
|
|
6
|
+
export var defaultRecorders = [contextRecorder, visibilityRecorder];
|
|
7
|
+
export var SEMANTIC_CAPS = { context: DEFAULT_SEMANTIC_CAP, visibility: DEFAULT_SEMANTIC_CAP };
|
|
7
8
|
export * from './types';
|
|
8
9
|
export { getDocumentIdentity } from './identity';
|
|
9
10
|
export function createSemanticCapture(config, host, recorders) {
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AAC/C,MAAM,CAAC,IAAM,gBAAgB,GAAgC,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;AACnG,MAAM,CAAC,IAAM,aAAa,GAAG,EAAE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC;AACjG,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,UAAU,qBAAqB,CACnC,MAA6B,EAC7B,IAAkB,EAClB,SAAyD;IAAzD,0BAAA,EAAA,4BAAyD;IAEzD,OAAO,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nimport { visibilityRecorder } from './recorders/visibility';\nimport { contextRecorder } from './recorders/context';\nimport type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';\n\nexport { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nexport { contextRecorder, visibilityRecorder };\nexport const defaultRecorders: readonly SemanticRecorder[] = [contextRecorder, visibilityRecorder];\nexport const SEMANTIC_CAPS = { context: DEFAULT_SEMANTIC_CAP, visibility: DEFAULT_SEMANTIC_CAP };\nexport * from './types';\nexport type { SemanticCapture } from './capture';\nexport { getDocumentIdentity } from './identity';\n\nexport function createSemanticCapture(\n config: SemanticCaptureConfig,\n host: SemanticHost,\n recorders: readonly SemanticRecorder[] = defaultRecorders,\n) {\n return createCapture(config, host, recorders, SEMANTIC_CAPS);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../../src/recorders/visibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,EAAE,gBAehC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Document visibility is independent of keyboard focus. */
|
|
2
|
+
export var visibilityRecorder = {
|
|
3
|
+
families: ['visibility'],
|
|
4
|
+
setup: function (context) {
|
|
5
|
+
var document = context.host.document;
|
|
6
|
+
var readState = function () { return (document.visibilityState === 'hidden' ? 'hidden' : 'visible'); };
|
|
7
|
+
var previous = readState();
|
|
8
|
+
var onVisibility = function () {
|
|
9
|
+
var state = readState();
|
|
10
|
+
if (state === previous)
|
|
11
|
+
return;
|
|
12
|
+
previous = state;
|
|
13
|
+
context.emit('visibility', { state: state });
|
|
14
|
+
};
|
|
15
|
+
document.addEventListener('visibilitychange', onVisibility, true);
|
|
16
|
+
return function () { return document.removeEventListener('visibilitychange', onVisibility, true); };
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=visibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.js","sourceRoot":"","sources":["../../../src/recorders/visibility.ts"],"names":[],"mappings":"AAEA,4DAA4D;AAC5D,MAAM,CAAC,IAAM,kBAAkB,GAAqB;IAClD,QAAQ,EAAE,CAAC,YAAY,CAAC;IACxB,KAAK,YAAC,OAAO;QACH,IAAA,QAAQ,GAAK,OAAO,CAAC,IAAI,SAAjB,CAAkB;QAClC,IAAM,SAAS,GAAG,cAAM,OAAA,CAAC,QAAQ,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,EAA9D,CAA8D,CAAC;QACvF,IAAI,QAAQ,GAAG,SAAS,EAAE,CAAC;QAC3B,IAAM,YAAY,GAAG;YACnB,IAAM,KAAK,GAAG,SAAS,EAAE,CAAC;YAC1B,IAAI,KAAK,KAAK,QAAQ;gBAAE,OAAO;YAC/B,QAAQ,GAAG,KAAK,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;QAClE,OAAO,cAAM,OAAA,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,YAAY,EAAE,IAAI,CAAC,EAApE,CAAoE,CAAC;IACpF,CAAC;CACF,CAAC","sourcesContent":["import type { SemanticRecorder } from '../types';\n\n/** Document visibility is independent of keyboard focus. */\nexport const visibilityRecorder: SemanticRecorder = {\n families: ['visibility'],\n setup(context) {\n const { document } = context.host;\n const readState = () => (document.visibilityState === 'hidden' ? 'hidden' : 'visible');\n let previous = readState();\n const onVisibility = () => {\n const state = readState();\n if (state === previous) return;\n previous = state;\n context.emit('visibility', { state });\n };\n document.addEventListener('visibilitychange', onVisibility, true);\n return () => document.removeEventListener('visibilitychange', onVisibility, true);\n },\n};\n"]}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -18,6 +18,9 @@ export interface SemanticEventEnvelope<Name extends string, Payload extends obje
|
|
|
18
18
|
}
|
|
19
19
|
/** Payloads exclude version and identity, which are owned by the runtime. */
|
|
20
20
|
export interface SemanticPayloads {
|
|
21
|
+
visibility: {
|
|
22
|
+
state: 'hidden' | 'visible';
|
|
23
|
+
};
|
|
21
24
|
context: {
|
|
22
25
|
sdk: string;
|
|
23
26
|
mask: 'light' | 'medium' | 'conservative';
|
package/lib/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3E,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AACD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AACD,oFAAoF;AACpF,MAAM,WAAW,qBAAqB,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM;IAChF,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CA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AM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IAChD,IAAI,EAAE,CAAC,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7F,EAAE,EAAE,CAAC,CAAC,SAAS,MAAM,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC;IACnG,yFAAyF;IACzF,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1D,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AACD,yEAAyE;AACzE,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,gBAAgB;IACnE,QAAQ,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,KAAK,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;CACjD"}
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,IAAM,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';\n\nexport const SEMANTIC_VERSION = 1;\nexport interface AnalyticsContext {\n present: boolean;\n autocapture: string[];\n}\nexport interface SemanticIdentity {\n readonly tab_id: string;\n readonly document_id: string;\n}\n/** Internal event envelope, independent of any event family or replay transport. */\nexport interface SemanticEventEnvelope<Name extends string, Payload extends object> {\n name: Name;\n timestamp: number;\n payload: Payload & SemanticIdentity & { v: typeof SEMANTIC_VERSION };\n}\n\n/** Payloads exclude version and identity, which are owned by the runtime. */\nexport interface SemanticPayloads {\n context: {\n sdk: string;\n mask: 'light' | 'medium' | 'conservative';\n css: { total: number; inlined: number; unreadable: number };\n viewport: { w: number; h: number };\n device: 'desktop' | 'tablet' | 'mobile';\n language: string;\n visibility_state: 'hidden' | 'visible';\n focused: boolean;\n user_agent: string;\n analytics_sdk: AnalyticsContext;\n caps_hit?: Partial<Record<SemanticFamily, number>>;\n };\n}\nexport type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;\nexport type SemanticEvent<P extends object = SemanticPayloads> = {\n [K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;\n}[SemanticFamily<P>];\nexport interface SemanticCaptureConfig<P extends object = SemanticPayloads> {\n enabled: boolean;\n /** Additional sampling within recorded replay sessions. Defaults to 1. */\n sampleRate?: number;\n /** Registered families are enabled unless explicitly false. */\n families?: Partial<Record<SemanticFamily<P>, boolean>>;\n}\nexport interface HostSignals {\n /** An accepted full snapshot, forwarded after the recorder is ready. */\n snapshot: undefined;\n}\nexport type Cleanup = () => void;\n/** The host owns transport; the runtime has no rrweb dependency. */\nexport interface SemanticHost<P extends object = SemanticPayloads> {\n document: Document;\n window: Window;\n sdk: string;\n getPrivacy: () => PrivacyConfig;\n getAnalyticsContext?: () => AnalyticsContext;\n inlineStylesheet?: boolean;\n emit: (event: SemanticEvent<P>) => void;\n /** Called lazily for accepted events. Defaults to document-scoped memory only. */\n getIdentity?: () => SemanticIdentity;\n now?: () => number;\n random?: () => number;\n onError?: (error: unknown) => void;\n}\nexport interface RecorderContext<P extends object = SemanticPayloads> {\n /** Register resources immediately so failed setup can roll them back. */\n onCleanup: (cleanup: Cleanup) => void;\n host: SemanticHost<P>;\n now: () => number;\n /** Check before expensive payload work. A rejected candidate increments the dropped count. */\n canEmit: (family: SemanticFamily<P>) => boolean;\n emit: <K extends SemanticFamily<P>>(family: K, payload: P[K], timestamp?: number) => boolean;\n on: <K extends keyof HostSignals>(signal: K, callback: (value: HostSignals[K]) => void) => Cleanup;\n /** Peek at dropped counts; a recorder can acknowledge them after successful delivery. */\n dropped: () => Partial<Record<SemanticFamily<P>, number>>;\n clearDropped: () => void;\n}\n/** A factory owns its listeners/timers and returns complete teardown. */\nexport interface SemanticRecorder<P extends object = SemanticPayloads> {\n families: readonly SemanticFamily<P>[];\n setup: (context: RecorderContext<P>) => Cleanup;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,IAAM,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';\n\nexport const SEMANTIC_VERSION = 1;\nexport interface AnalyticsContext {\n present: boolean;\n autocapture: string[];\n}\nexport interface SemanticIdentity {\n readonly tab_id: string;\n readonly document_id: string;\n}\n/** Internal event envelope, independent of any event family or replay transport. */\nexport interface SemanticEventEnvelope<Name extends string, Payload extends object> {\n name: Name;\n timestamp: number;\n payload: Payload & SemanticIdentity & { v: typeof SEMANTIC_VERSION };\n}\n\n/** Payloads exclude version and identity, which are owned by the runtime. */\nexport interface SemanticPayloads {\n visibility: { state: 'hidden' | 'visible' };\n context: {\n sdk: string;\n mask: 'light' | 'medium' | 'conservative';\n css: { total: number; inlined: number; unreadable: number };\n viewport: { w: number; h: number };\n device: 'desktop' | 'tablet' | 'mobile';\n language: string;\n visibility_state: 'hidden' | 'visible';\n focused: boolean;\n user_agent: string;\n analytics_sdk: AnalyticsContext;\n caps_hit?: Partial<Record<SemanticFamily, number>>;\n };\n}\nexport type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;\nexport type SemanticEvent<P extends object = SemanticPayloads> = {\n [K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;\n}[SemanticFamily<P>];\nexport interface SemanticCaptureConfig<P extends object = SemanticPayloads> {\n enabled: boolean;\n /** Additional sampling within recorded replay sessions. Defaults to 1. */\n sampleRate?: number;\n /** Registered families are enabled unless explicitly false. */\n families?: Partial<Record<SemanticFamily<P>, boolean>>;\n}\nexport interface HostSignals {\n /** An accepted full snapshot, forwarded after the recorder is ready. */\n snapshot: undefined;\n}\nexport type Cleanup = () => void;\n/** The host owns transport; the runtime has no rrweb dependency. */\nexport interface SemanticHost<P extends object = SemanticPayloads> {\n document: Document;\n window: Window;\n sdk: string;\n getPrivacy: () => PrivacyConfig;\n getAnalyticsContext?: () => AnalyticsContext;\n inlineStylesheet?: boolean;\n emit: (event: SemanticEvent<P>) => void;\n /** Called lazily for accepted events. Defaults to document-scoped memory only. */\n getIdentity?: () => SemanticIdentity;\n now?: () => number;\n random?: () => number;\n onError?: (error: unknown) => void;\n}\nexport interface RecorderContext<P extends object = SemanticPayloads> {\n /** Register resources immediately so failed setup can roll them back. */\n onCleanup: (cleanup: Cleanup) => void;\n host: SemanticHost<P>;\n now: () => number;\n /** Check before expensive payload work. A rejected candidate increments the dropped count. */\n canEmit: (family: SemanticFamily<P>) => boolean;\n emit: <K extends SemanticFamily<P>>(family: K, payload: P[K], timestamp?: number) => boolean;\n on: <K extends keyof HostSignals>(signal: K, callback: (value: HostSignals[K]) => void) => Cleanup;\n /** Peek at dropped counts; a recorder can acknowledge them after successful delivery. */\n dropped: () => Partial<Record<SemanticFamily<P>, number>>;\n clearDropped: () => void;\n}\n/** A factory owns its listeners/timers and returns complete teardown. */\nexport interface SemanticRecorder<P extends object = SemanticPayloads> {\n families: readonly SemanticFamily<P>[];\n setup: (context: RecorderContext<P>) => Cleanup;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/amp-semantic",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Composable semantic event capture with browser context for Amplitude",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/index.js",
|
|
7
7
|
"module": "lib/esm/index.js",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"build:es5": "tsc -p tsconfig.es5.json",
|
|
34
34
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
35
35
|
"test": "jest",
|
|
36
|
-
"lint": "eslint '{src,test}/**/*.ts'",
|
|
37
|
-
"typecheck": "tsc -p tsconfig.json"
|
|
36
|
+
"lint": "eslint '{src,test,e2e}/**/*.ts'",
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
38
|
+
"test:playwright": "playwright test --config playwright.config.ts"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/schema.json
CHANGED
|
@@ -95,6 +95,10 @@
|
|
|
95
95
|
"context": {
|
|
96
96
|
"type": "integer",
|
|
97
97
|
"minimum": 0
|
|
98
|
+
},
|
|
99
|
+
"visibility": {
|
|
100
|
+
"type": "integer",
|
|
101
|
+
"minimum": 0
|
|
98
102
|
}
|
|
99
103
|
},
|
|
100
104
|
"additionalProperties": false
|
|
@@ -132,6 +136,58 @@
|
|
|
132
136
|
},
|
|
133
137
|
"required": ["type", "timestamp", "data"],
|
|
134
138
|
"additionalProperties": false
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"type": "object",
|
|
142
|
+
"properties": {
|
|
143
|
+
"type": {
|
|
144
|
+
"const": 5
|
|
145
|
+
},
|
|
146
|
+
"timestamp": {
|
|
147
|
+
"type": "number"
|
|
148
|
+
},
|
|
149
|
+
"data": {
|
|
150
|
+
"type": "object",
|
|
151
|
+
"properties": {
|
|
152
|
+
"tag": {
|
|
153
|
+
"const": "amp-semantic/visibility"
|
|
154
|
+
},
|
|
155
|
+
"payload": {
|
|
156
|
+
"type": "object",
|
|
157
|
+
"properties": {
|
|
158
|
+
"state": {
|
|
159
|
+
"enum": ["hidden", "visible"]
|
|
160
|
+
},
|
|
161
|
+
"focused": {
|
|
162
|
+
"type": "boolean",
|
|
163
|
+
"description": "Legacy observation-time focus snapshot; no longer emitted by visibility producers."
|
|
164
|
+
},
|
|
165
|
+
"trigger": {
|
|
166
|
+
"enum": ["visibilitychange", "focus", "blur"],
|
|
167
|
+
"description": "Legacy trigger; new visibility events emit only state plus version and identity."
|
|
168
|
+
},
|
|
169
|
+
"tab_id": {
|
|
170
|
+
"type": "string",
|
|
171
|
+
"minLength": 1
|
|
172
|
+
},
|
|
173
|
+
"document_id": {
|
|
174
|
+
"type": "string",
|
|
175
|
+
"minLength": 1
|
|
176
|
+
},
|
|
177
|
+
"v": {
|
|
178
|
+
"const": 1
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"required": ["state", "v", "tab_id", "document_id"],
|
|
182
|
+
"additionalProperties": false
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
"required": ["tag", "payload"],
|
|
186
|
+
"additionalProperties": false
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
"required": ["type", "timestamp", "data"],
|
|
190
|
+
"additionalProperties": false
|
|
135
191
|
}
|
|
136
192
|
]
|
|
137
193
|
}
|