@webority/analytics 0.1.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/analytics",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "exports": {
package/src/analytics.js CHANGED
@@ -12,6 +12,13 @@ export function initAnalytics(config) {
12
12
  enabled: config.enabled ?? true,
13
13
  getConsent: config.getConsent ?? null,
14
14
  logger: config.logger ?? null,
15
+ // Off unless the product asks: replay records page content, so turning it on is the
16
+ // product's disclosed decision, never a package default.
17
+ sessionRecording: {
18
+ enabled: config.sessionRecording?.enabled ?? false,
19
+ maskAllInputs: config.sessionRecording?.maskAllInputs ?? true,
20
+ maskTextSelector: config.sessionRecording?.maskTextSelector ?? null,
21
+ },
15
22
  });
16
23
 
17
24
  if (isActive()) {
@@ -13,12 +13,7 @@ export async function ensurePosthogInitialized() {
13
13
  const config = state.config;
14
14
  state.posthogInitPromise = import("posthog-js").then((module) => {
15
15
  const posthog = module.default ?? module;
16
- posthog.init(config.clientKey, {
17
- api_host: config.host,
18
- autocapture: false,
19
- capture_pageview: true,
20
- persistence: "localStorage",
21
- });
16
+ posthog.init(config.clientKey, buildInitOptions(config));
22
17
  posthog.register({ product: config.product, surface: config.surface });
23
18
  state.posthogInstance = posthog;
24
19
  return posthog;
@@ -26,3 +21,26 @@ export async function ensurePosthogInitialized() {
26
21
 
27
22
  return state.posthogInitPromise;
28
23
  }
24
+
25
+ /**
26
+ * The posthog-js init options for a config. Pure, so the smoke test can assert the mapping
27
+ * without a browser: replay stays off unless the product enabled it, and the masking choices
28
+ * ride through only when it is on.
29
+ */
30
+ export function buildInitOptions(config) {
31
+ const recording = config.sessionRecording ?? { enabled: false };
32
+ const options = {
33
+ api_host: config.host,
34
+ autocapture: false,
35
+ capture_pageview: true,
36
+ persistence: "localStorage",
37
+ disable_session_recording: !recording.enabled,
38
+ };
39
+ if (recording.enabled) {
40
+ options.session_recording = {
41
+ maskAllInputs: recording.maskAllInputs ?? true,
42
+ ...(recording.maskTextSelector ? { maskTextSelector: recording.maskTextSelector } : {}),
43
+ };
44
+ }
45
+ return options;
46
+ }