@getsoren/shared-module 2.61.0 → 2.62.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.
@@ -58,13 +58,22 @@ export interface InitializeAmplitudeProps {
58
58
  * overrides the remote rate for this app and disables Dynamic Sampling org-wide.
59
59
  */
60
60
  sessionReplaySampleRate?: number;
61
+ /**
62
+ * Id of the authenticated user, `undefined` while nobody is signed in. Amplitude bills every distinct visitor as a
63
+ * Monthly Tracked User, so nothing is tracked until a user id is known: no SDK init, no session, no page view, no
64
+ * replay on the sign-in page. Signing out (back to `undefined`) opts the SDK out until the next user id arrives.
65
+ * Required on purpose, so an app cannot start tracking anonymous visitors by forgetting it.
66
+ */
67
+ userId: string | undefined;
61
68
  }
62
69
  /**
63
- * Initializes the Amplitude SDK once at mount:
70
+ * Initializes the Amplitude SDK once a user is signed in, and only tracks while one is:
71
+ * - tracks authenticated users only: anonymous visitors (sign-in page, bots, link previews) are never sent, since
72
+ * Amplitude bills each of them as a Monthly Tracked User,
64
73
  * - enables click autocapture (with our feature selector) and rage/dead click detection, the data behind heatmaps,
65
74
  * - tracks SPA page views on path changes only (query-string churn from filters doesn't count as a new view),
66
75
  * - registers the session replay plugin, remote-controlled sample rate by default (Dynamic Sampling ready),
67
76
  * - registers an enrichment plugin that adds `platform` to every event's properties.
68
77
  */
69
- declare const InitializeAmplitude: ({ apiKey, appVersion, sessionReplaySampleRate, serverZone, elementInteractions, frustrationInteractions, platform, sessionReplayPrivacy, ...props }: InitializeAmplitudeProps) => null;
78
+ declare const InitializeAmplitude: ({ apiKey, appVersion, sessionReplaySampleRate, serverZone, elementInteractions, frustrationInteractions, platform, sessionReplayPrivacy, userId, ...props }: InitializeAmplitudeProps) => null;
70
79
  export default InitializeAmplitude;
@@ -0,0 +1 @@
1
+ export {};
package/dist/main.js CHANGED
@@ -206,31 +206,32 @@ var f = 3e4, p = 1e3, m = 1e4, h = (e) => Array.isArray(e) ? e.map(h) : typeof e
206
206
  deadClicks: !0,
207
207
  rageClicks: !0,
208
208
  ...e === !0 ? {} : e
209
- }, N = ({ apiKey: e, appVersion: t, sessionReplaySampleRate: n, serverZone: r, elementInteractions: i = !0, frustrationInteractions: c = !0, platform: u = "desktop", sessionReplayPrivacy: d = te, ...f }) => {
210
- let { libraries: p } = a(y), m = f.amplitude || p?.amplitude, h = l({
209
+ }, N = ({ apiKey: e, appVersion: t, sessionReplaySampleRate: n, serverZone: r, elementInteractions: i = !0, frustrationInteractions: c = !0, platform: d = "desktop", sessionReplayPrivacy: f = te, userId: p, ...m }) => {
210
+ let [h, g] = u(!!p), { libraries: _ } = a(y), v = m.amplitude || _?.amplitude, b = l({
211
211
  elementInteractions: i,
212
212
  frustrationInteractions: c,
213
- sessionReplayPrivacy: d
214
- });
215
- return s(() => {
216
- h.current = {
213
+ sessionReplayPrivacy: f
214
+ }), x = l(p);
215
+ return p && !h && g(!0), s(() => {
216
+ b.current = {
217
217
  elementInteractions: i,
218
218
  frustrationInteractions: c,
219
- sessionReplayPrivacy: d
220
- };
219
+ sessionReplayPrivacy: f
220
+ }, x.current = p;
221
221
  }), o(() => {
222
- let i = m?.analytics, a = m?.sessionReplayPlugin;
223
- if (!(e && i)) return;
224
- let { elementInteractions: o, frustrationInteractions: s, sessionReplayPrivacy: c } = h.current, l = "platform-enrichment", d = j(o, i.Types?.DEFAULT_CSS_SELECTOR_ALLOWLIST ?? A);
225
- return i.init(e, {
222
+ let i = v?.analytics, a = v?.sessionReplayPlugin;
223
+ if (!(e && i && h)) return;
224
+ let { elementInteractions: o, frustrationInteractions: s, sessionReplayPrivacy: c } = b.current, l = x.current, u = !l, f = "platform-enrichment", p = j(o, i.Types?.DEFAULT_CSS_SELECTOR_ALLOWLIST ?? A);
225
+ return i.init(e, l, {
226
226
  appVersion: t,
227
227
  autocapture: {
228
- elementInteractions: d,
229
- frustrationInteractions: M(s, d !== !1),
228
+ elementInteractions: p,
229
+ frustrationInteractions: M(s, p !== !1),
230
230
  pageViews: { trackHistoryChanges: "pathOnly" }
231
231
  },
232
+ optOut: u,
232
233
  serverZone: r
233
- }), a && i.add(a({
234
+ }), i.setOptOut(u), a && i.add(a({
234
235
  privacyConfig: c,
235
236
  ...n === void 0 ? {} : { sampleRate: n }
236
237
  })), i.add({
@@ -238,21 +239,36 @@ var f = 3e4, p = 1e3, m = 1e4, h = (e) => Array.isArray(e) ? e.map(h) : typeof e
238
239
  ...e,
239
240
  event_properties: {
240
241
  ...e.event_properties,
241
- platform: u
242
+ platform: d
242
243
  }
243
244
  }),
244
- name: l,
245
+ name: f,
245
246
  type: "enrichment"
246
247
  }), () => {
247
- a && i.remove("@amplitude/plugin-session-replay-browser"), i.remove(l);
248
+ a && i.remove("@amplitude/plugin-session-replay-browser"), i.remove(f), i.setOptOut(!0);
248
249
  };
249
250
  }, [
250
251
  e,
251
- m,
252
+ v,
252
253
  t,
253
- u,
254
+ d,
254
255
  r,
255
- n
256
+ n,
257
+ h
258
+ ]), o(() => {
259
+ let t = v?.analytics;
260
+ if (e && t && h) {
261
+ if (!p) {
262
+ t.setOptOut(!0);
263
+ return;
264
+ }
265
+ t.setUserId(p), t.setOptOut(!1);
266
+ }
267
+ }, [
268
+ e,
269
+ v,
270
+ h,
271
+ p
256
272
  ]), null;
257
273
  }, P = (() => {
258
274
  try {
@@ -547,7 +563,7 @@ var f = 3e4, p = 1e3, m = 1e4, h = (e) => Array.isArray(e) ? e.map(h) : typeof e
547
563
  return {
548
564
  identify: n,
549
565
  reset: i(() => {
550
- t && t.reset();
566
+ t && (t.setOptOut(!0), t.reset());
551
567
  }, [t]),
552
568
  setGroup: r,
553
569
  track: o
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getsoren/shared-module",
3
- "version": "2.61.0",
3
+ "version": "2.62.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "types": "./dist/main.d.ts",