@shware/analytics 11.1.0 → 11.3.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.
Files changed (56) hide show
  1. package/README.md +9 -5
  2. package/dist/index.cjs +4 -2
  3. package/dist/index.d.cts +3 -2
  4. package/dist/index.d.mts +3 -2
  5. package/dist/index.mjs +3 -2
  6. package/dist/server/openai-conversions-api.cjs +2 -2
  7. package/dist/server/openai-conversions-api.cjs.map +1 -1
  8. package/dist/server/openai-conversions-api.d.cts.map +1 -1
  9. package/dist/server/openai-conversions-api.d.mts.map +1 -1
  10. package/dist/server/openai-conversions-api.mjs +3 -3
  11. package/dist/server/openai-conversions-api.mjs.map +1 -1
  12. package/dist/third-parties/ignored-events.cjs +7 -1
  13. package/dist/third-parties/ignored-events.cjs.map +1 -1
  14. package/dist/third-parties/ignored-events.d.cts.map +1 -1
  15. package/dist/third-parties/ignored-events.d.mts.map +1 -1
  16. package/dist/third-parties/ignored-events.mjs +7 -1
  17. package/dist/third-parties/ignored-events.mjs.map +1 -1
  18. package/dist/third-parties/microsoft-uet.cjs +2 -2
  19. package/dist/third-parties/microsoft-uet.cjs.map +1 -1
  20. package/dist/third-parties/microsoft-uet.mjs +1 -1
  21. package/dist/third-parties/microsoft-uet.mjs.map +1 -1
  22. package/dist/third-parties/openai-pixel.cjs +1 -0
  23. package/dist/third-parties/openai-pixel.cjs.map +1 -1
  24. package/dist/third-parties/openai-pixel.d.cts.map +1 -1
  25. package/dist/third-parties/openai-pixel.d.mts.map +1 -1
  26. package/dist/third-parties/openai-pixel.mjs +2 -1
  27. package/dist/third-parties/openai-pixel.mjs.map +1 -1
  28. package/dist/track/index.cjs +4 -4
  29. package/dist/track/index.cjs.map +1 -1
  30. package/dist/track/index.mjs +1 -1
  31. package/dist/track/index.mjs.map +1 -1
  32. package/dist/track/oaiq.cjs +17 -0
  33. package/dist/track/oaiq.cjs.map +1 -1
  34. package/dist/track/oaiq.d.cts +8 -0
  35. package/dist/track/oaiq.d.cts.map +1 -1
  36. package/dist/track/oaiq.d.mts +8 -0
  37. package/dist/track/oaiq.d.mts.map +1 -1
  38. package/dist/track/oaiq.mjs +17 -1
  39. package/dist/track/oaiq.mjs.map +1 -1
  40. package/dist/visitor/id.cjs +25 -0
  41. package/dist/visitor/id.cjs.map +1 -0
  42. package/dist/visitor/id.d.cts +13 -0
  43. package/dist/visitor/id.d.cts.map +1 -0
  44. package/dist/visitor/id.d.mts +13 -0
  45. package/dist/visitor/id.d.mts.map +1 -0
  46. package/dist/visitor/id.mjs +24 -0
  47. package/dist/visitor/id.mjs.map +1 -0
  48. package/dist/visitor/index.cjs +24 -29
  49. package/dist/visitor/index.cjs.map +1 -1
  50. package/dist/visitor/index.d.cts +15 -9
  51. package/dist/visitor/index.d.cts.map +1 -1
  52. package/dist/visitor/index.d.mts +15 -9
  53. package/dist/visitor/index.d.mts.map +1 -1
  54. package/dist/visitor/index.mjs +23 -29
  55. package/dist/visitor/index.mjs.map +1 -1
  56. package/package.json +1 -1
@@ -1,38 +1,33 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_setup_index = require("../setup/index.cjs");
3
- const require_constants_storage = require("../constants/storage.cjs");
4
- let _shware_utils = require("@shware/utils");
5
- let uuid = require("uuid");
3
+ const require_visitor_id = require("./id.cjs");
4
+ const require_track_index = require("../track/index.cjs");
6
5
  //#region src/visitor/index.ts
7
6
  /**
8
- * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so
9
- * it exists the moment the page loads. The first events, and the beacon of a visit left within a
10
- * second, go out without waiting for a round trip; the server creates the visitor from its first
11
- * events. An id a server issued to an older client is kept as it is: the visitor continues.
7
+ * The event that binds the visitor to the user who signed in on it: the server sets the visitor's
8
+ * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the
9
+ * batch — which also creates the visitor when it is new, so the binding can never arrive before it.
10
+ */
11
+ const IDENTIFY_EVENT = "identify";
12
+ /** The user this page has identified the visitor as: identify once per user, not per call. */
13
+ let identified;
14
+ /**
15
+ * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,
16
+ * and the server through an `identify` event, sent when the user differs from the one this page
17
+ * last identified — a host calls this on every page load once someone is signed in. Like any
18
+ * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
19
+ * only, never stored with the event.
12
20
  *
13
- * Needs a server that creates visitors from events (see the README, "Visitors"); one that still
14
- * only creates them on `POST /visitors` rejects the events of a new visitor.
21
+ * Synchronous and never throws: sign-in must not fail on analytics.
15
22
  */
16
- function visitorId() {
17
- const stored = require_setup_index.config.storage.getItem(require_constants_storage.keys.visitor_id);
18
- if (stored && stored !== "undefined") return stored;
19
- const id = (0, uuid.v7)();
20
- require_setup_index.config.storage.setItem(require_constants_storage.keys.visitor_id, id);
21
- return id;
22
- }
23
- async function setVisitor(dto) {
24
- const id = visitorId();
25
- const response = await (0, _shware_utils.fetch)(`${require_setup_index.config.endpoint}/visitors/${id}`, {
26
- method: "PATCH",
27
- credentials: "include",
28
- headers: await require_setup_index.config.getHeaders(),
29
- body: JSON.stringify(dto)
30
- });
31
- if (!response.ok) throw new Error("Failed to set visitor");
32
- const data = await response.json();
23
+ function setVisitor(dto) {
24
+ if (dto.user_id && dto.user_id !== identified) {
25
+ identified = dto.user_id;
26
+ require_track_index.track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });
27
+ }
33
28
  const identity = {
34
29
  ...dto,
35
- distinct_id: data.distinct_id ?? null
30
+ distinct_id: dto.user_id ?? null
36
31
  };
37
32
  require_setup_index.config.thirdPartyUserSetters.forEach((setter) => {
38
33
  try {
@@ -41,10 +36,10 @@ async function setVisitor(dto) {
41
36
  if (e instanceof Error) console.log(e.message);
42
37
  }
43
38
  });
44
- return data;
45
39
  }
46
40
  //#endregion
41
+ exports.IDENTIFY_EVENT = IDENTIFY_EVENT;
47
42
  exports.setVisitor = setVisitor;
48
- exports.visitorId = visitorId;
43
+ exports.visitorId = require_visitor_id.visitorId;
49
44
 
50
45
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["config","keys","uuidv7","fetch"],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import { fetch } from '@shware/utils';\nimport { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport type { Visitor } from './types';\n\n/**\n * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so\n * it exists the moment the page loads. The first events, and the beacon of a visit left within a\n * second, go out without waiting for a round trip; the server creates the visitor from its first\n * events. An id a server issued to an older client is kept as it is: the visitor continues.\n *\n * Needs a server that creates visitors from events (see the README, \"Visitors\"); one that still\n * only creates them on `POST /visitors` rejects the events of a new visitor.\n */\nexport function visitorId(): string {\n const stored = config.storage.getItem(keys.visitor_id);\n if (stored && stored !== 'undefined') return stored;\n const id = uuidv7();\n config.storage.setItem(keys.visitor_id, id);\n return id;\n}\n\nexport async function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>) {\n const id = visitorId();\n const response = await fetch(`${config.endpoint}/visitors/${id}`, {\n method: 'PATCH',\n credentials: 'include',\n headers: await config.getHeaders(),\n body: JSON.stringify(dto),\n });\n\n if (!response.ok) throw new Error('Failed to set visitor');\n const data = (await response.json()) as Visitor;\n\n // Setters get the server's distinct_id — the person the visitor now belongs to — not anything\n // the client could have said about it.\n const identity = { ...dto, distinct_id: data.distinct_id ?? null };\n config.thirdPartyUserSetters.forEach((setter) => {\n try {\n setter(identity);\n } catch (e: unknown) {\n // The visitor was updated before this ran, so a third-party setter throwing must not reject\n // a call that already succeeded.\n if (e instanceof Error) console.log(e.message);\n }\n });\n return data;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,YAAoB;CAClC,MAAM,SAASA,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,UAAU;CACrD,IAAI,UAAU,WAAW,aAAa,OAAO;CAC7C,MAAM,MAAA,GAAKC,KAAAA,GAAAA,CAAO;CAClB,oBAAA,OAAO,QAAQ,QAAQD,0BAAAA,KAAK,YAAY,EAAE;CAC1C,OAAO;AACT;AAEA,eAAsB,WAAW,KAAqC;CACpE,MAAM,KAAK,UAAU;CACrB,MAAM,WAAW,OAAA,GAAME,cAAAA,MAAAA,CAAM,GAAGH,oBAAAA,OAAO,SAAS,YAAY,MAAM;EAChE,QAAQ;EACR,aAAa;EACb,SAAS,MAAMA,oBAAAA,OAAO,WAAW;EACjC,MAAM,KAAK,UAAU,GAAG;CAC1B,CAAC;CAED,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,uBAAuB;CACzD,MAAM,OAAQ,MAAM,SAAS,KAAK;CAIlC,MAAM,WAAW;EAAE,GAAG;EAAK,aAAa,KAAK,eAAe;CAAK;CACjE,oBAAA,OAAO,sBAAsB,SAAS,WAAW;EAC/C,IAAI;GACF,OAAO,QAAQ;EACjB,SAAS,GAAY;GAGnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;CACD,OAAO;AACT"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport { track } from '../track/index';\n\nexport { visitorId } from './id';\n\n/**\n * The event that binds the visitor to the user who signed in on it: the server sets the visitor's\n * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the\n * batch — which also creates the visitor when it is new, so the binding can never arrive before it.\n */\nexport const IDENTIFY_EVENT = 'identify';\n\n/** The user this page has identified the visitor as: identify once per user, not per call. */\nlet identified: string | undefined;\n\n/**\n * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,\n * and the server through an `identify` event, sent when the user differs from the one this page\n * last identified — a host calls this on every page load once someone is signed in. Like any\n * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters\n * only, never stored with the event.\n *\n * Synchronous and never throws: sign-in must not fail on analytics.\n */\nexport function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>) {\n if (dto.user_id && dto.user_id !== identified) {\n identified = dto.user_id;\n track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });\n }\n\n // Once bound, the server's person key for the visitor is the user's id, so the setters are told\n // that rather than waiting for the server to say it.\n const identity = { ...dto, distinct_id: dto.user_id ?? null };\n config.thirdPartyUserSetters.forEach((setter) => {\n try {\n setter(identity);\n } catch (e: unknown) {\n // One third-party script does not get to stop the others.\n if (e instanceof Error) console.log(e.message);\n }\n });\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAa,iBAAiB;;AAG9B,IAAI;;;;;;;;;;AAWJ,SAAgB,WAAW,KAAqC;CAC9D,IAAI,IAAI,WAAW,IAAI,YAAY,YAAY;EAC7C,aAAa,IAAI;EACjB,oBAAA,MAAM,gBAAgB,EAAE,SAAS,IAAI,QAAQ,GAAG,EAAE,0BAA0B,MAAM,CAAC;CACrF;CAIA,MAAM,WAAW;EAAE,GAAG;EAAK,aAAa,IAAI,WAAW;CAAK;CAC5D,oBAAA,OAAO,sBAAsB,SAAS,WAAW;EAC/C,IAAI;GACF,OAAO,QAAQ;EACjB,SAAS,GAAY;GAEnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;AACH"}
@@ -1,16 +1,22 @@
1
1
  import { UpdateVisitorDTO } from "../schema/index.cjs";
2
- import { Visitor } from "./types.cjs";
2
+ import { visitorId } from "./id.cjs";
3
3
  //#region src/visitor/index.d.ts
4
4
  /**
5
- * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so
6
- * it exists the moment the page loads. The first events, and the beacon of a visit left within a
7
- * second, go out without waiting for a round trip; the server creates the visitor from its first
8
- * events. An id a server issued to an older client is kept as it is: the visitor continues.
5
+ * The event that binds the visitor to the user who signed in on it: the server sets the visitor's
6
+ * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the
7
+ * batch — which also creates the visitor when it is new, so the binding can never arrive before it.
8
+ */
9
+ export declare const IDENTIFY_EVENT = "identify";
10
+ /**
11
+ * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,
12
+ * and the server through an `identify` event, sent when the user differs from the one this page
13
+ * last identified — a host calls this on every page load once someone is signed in. Like any
14
+ * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
15
+ * only, never stored with the event.
9
16
  *
10
- * Needs a server that creates visitors from events (see the README, "Visitors"); one that still
11
- * only creates them on `POST /visitors` rejects the events of a new visitor.
17
+ * Synchronous and never throws: sign-in must not fail on analytics.
12
18
  */
13
- export declare function visitorId(): string;
14
- export declare function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>): Promise<Visitor>;
19
+ export declare function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>): void;
15
20
  //#endregion
21
+ export { visitorId };
16
22
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;;;;;wBAgBgB;wBAQM,WAAW,KAAK,KAAK,4BAAyB,QAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa;;;;;;;;;;wBAcG,WAAW,KAAK,KAAK"}
@@ -1,16 +1,22 @@
1
1
  import { UpdateVisitorDTO } from "../schema/index.mjs";
2
- import { Visitor } from "./types.mjs";
2
+ import { visitorId } from "./id.mjs";
3
3
  //#region src/visitor/index.d.ts
4
4
  /**
5
- * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so
6
- * it exists the moment the page loads. The first events, and the beacon of a visit left within a
7
- * second, go out without waiting for a round trip; the server creates the visitor from its first
8
- * events. An id a server issued to an older client is kept as it is: the visitor continues.
5
+ * The event that binds the visitor to the user who signed in on it: the server sets the visitor's
6
+ * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the
7
+ * batch — which also creates the visitor when it is new, so the binding can never arrive before it.
8
+ */
9
+ export declare const IDENTIFY_EVENT = "identify";
10
+ /**
11
+ * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,
12
+ * and the server through an `identify` event, sent when the user differs from the one this page
13
+ * last identified — a host calls this on every page load once someone is signed in. Like any
14
+ * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
15
+ * only, never stored with the event.
9
16
  *
10
- * Needs a server that creates visitors from events (see the README, "Visitors"); one that still
11
- * only creates them on `POST /visitors` rejects the events of a new visitor.
17
+ * Synchronous and never throws: sign-in must not fail on analytics.
12
18
  */
13
- export declare function visitorId(): string;
14
- export declare function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>): Promise<Visitor>;
19
+ export declare function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>): void;
15
20
  //#endregion
21
+ export { visitorId };
16
22
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;;;;;wBAgBgB;wBAQM,WAAW,KAAK,KAAK,4BAAyB,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa;;;;;;;;;;wBAcG,WAAW,KAAK,KAAK"}
@@ -1,37 +1,32 @@
1
1
  import { config } from "../setup/index.mjs";
2
- import { keys } from "../constants/storage.mjs";
3
- import { fetch } from "@shware/utils";
4
- import { v7 } from "uuid";
2
+ import { visitorId } from "./id.mjs";
3
+ import { track } from "../track/index.mjs";
5
4
  //#region src/visitor/index.ts
6
5
  /**
7
- * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so
8
- * it exists the moment the page loads. The first events, and the beacon of a visit left within a
9
- * second, go out without waiting for a round trip; the server creates the visitor from its first
10
- * events. An id a server issued to an older client is kept as it is: the visitor continues.
6
+ * The event that binds the visitor to the user who signed in on it: the server sets the visitor's
7
+ * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the
8
+ * batch — which also creates the visitor when it is new, so the binding can never arrive before it.
9
+ */
10
+ const IDENTIFY_EVENT = "identify";
11
+ /** The user this page has identified the visitor as: identify once per user, not per call. */
12
+ let identified;
13
+ /**
14
+ * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,
15
+ * and the server through an `identify` event, sent when the user differs from the one this page
16
+ * last identified — a host calls this on every page load once someone is signed in. Like any
17
+ * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
18
+ * only, never stored with the event.
11
19
  *
12
- * Needs a server that creates visitors from events (see the README, "Visitors"); one that still
13
- * only creates them on `POST /visitors` rejects the events of a new visitor.
20
+ * Synchronous and never throws: sign-in must not fail on analytics.
14
21
  */
15
- function visitorId() {
16
- const stored = config.storage.getItem(keys.visitor_id);
17
- if (stored && stored !== "undefined") return stored;
18
- const id = v7();
19
- config.storage.setItem(keys.visitor_id, id);
20
- return id;
21
- }
22
- async function setVisitor(dto) {
23
- const id = visitorId();
24
- const response = await fetch(`${config.endpoint}/visitors/${id}`, {
25
- method: "PATCH",
26
- credentials: "include",
27
- headers: await config.getHeaders(),
28
- body: JSON.stringify(dto)
29
- });
30
- if (!response.ok) throw new Error("Failed to set visitor");
31
- const data = await response.json();
22
+ function setVisitor(dto) {
23
+ if (dto.user_id && dto.user_id !== identified) {
24
+ identified = dto.user_id;
25
+ track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });
26
+ }
32
27
  const identity = {
33
28
  ...dto,
34
- distinct_id: data.distinct_id ?? null
29
+ distinct_id: dto.user_id ?? null
35
30
  };
36
31
  config.thirdPartyUserSetters.forEach((setter) => {
37
32
  try {
@@ -40,9 +35,8 @@ async function setVisitor(dto) {
40
35
  if (e instanceof Error) console.log(e.message);
41
36
  }
42
37
  });
43
- return data;
44
38
  }
45
39
  //#endregion
46
- export { setVisitor, visitorId };
40
+ export { IDENTIFY_EVENT, setVisitor, visitorId };
47
41
 
48
42
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["uuidv7"],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import { fetch } from '@shware/utils';\nimport { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport type { Visitor } from './types';\n\n/**\n * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so\n * it exists the moment the page loads. The first events, and the beacon of a visit left within a\n * second, go out without waiting for a round trip; the server creates the visitor from its first\n * events. An id a server issued to an older client is kept as it is: the visitor continues.\n *\n * Needs a server that creates visitors from events (see the README, \"Visitors\"); one that still\n * only creates them on `POST /visitors` rejects the events of a new visitor.\n */\nexport function visitorId(): string {\n const stored = config.storage.getItem(keys.visitor_id);\n if (stored && stored !== 'undefined') return stored;\n const id = uuidv7();\n config.storage.setItem(keys.visitor_id, id);\n return id;\n}\n\nexport async function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>) {\n const id = visitorId();\n const response = await fetch(`${config.endpoint}/visitors/${id}`, {\n method: 'PATCH',\n credentials: 'include',\n headers: await config.getHeaders(),\n body: JSON.stringify(dto),\n });\n\n if (!response.ok) throw new Error('Failed to set visitor');\n const data = (await response.json()) as Visitor;\n\n // Setters get the server's distinct_id — the person the visitor now belongs to — not anything\n // the client could have said about it.\n const identity = { ...dto, distinct_id: data.distinct_id ?? null };\n config.thirdPartyUserSetters.forEach((setter) => {\n try {\n setter(identity);\n } catch (e: unknown) {\n // The visitor was updated before this ran, so a third-party setter throwing must not reject\n // a call that already succeeded.\n if (e instanceof Error) console.log(e.message);\n }\n });\n return data;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAgB,YAAoB;CAClC,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,UAAU;CACrD,IAAI,UAAU,WAAW,aAAa,OAAO;CAC7C,MAAM,KAAKA,GAAO;CAClB,OAAO,QAAQ,QAAQ,KAAK,YAAY,EAAE;CAC1C,OAAO;AACT;AAEA,eAAsB,WAAW,KAAqC;CACpE,MAAM,KAAK,UAAU;CACrB,MAAM,WAAW,MAAM,MAAM,GAAG,OAAO,SAAS,YAAY,MAAM;EAChE,QAAQ;EACR,aAAa;EACb,SAAS,MAAM,OAAO,WAAW;EACjC,MAAM,KAAK,UAAU,GAAG;CAC1B,CAAC;CAED,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,uBAAuB;CACzD,MAAM,OAAQ,MAAM,SAAS,KAAK;CAIlC,MAAM,WAAW;EAAE,GAAG;EAAK,aAAa,KAAK,eAAe;CAAK;CACjE,OAAO,sBAAsB,SAAS,WAAW;EAC/C,IAAI;GACF,OAAO,QAAQ;EACjB,SAAS,GAAY;GAGnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;CACD,OAAO;AACT"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport { track } from '../track/index';\n\nexport { visitorId } from './id';\n\n/**\n * The event that binds the visitor to the user who signed in on it: the server sets the visitor's\n * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the\n * batch — which also creates the visitor when it is new, so the binding can never arrive before it.\n */\nexport const IDENTIFY_EVENT = 'identify';\n\n/** The user this page has identified the visitor as: identify once per user, not per call. */\nlet identified: string | undefined;\n\n/**\n * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,\n * and the server through an `identify` event, sent when the user differs from the one this page\n * last identified — a host calls this on every page load once someone is signed in. Like any\n * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters\n * only, never stored with the event.\n *\n * Synchronous and never throws: sign-in must not fail on analytics.\n */\nexport function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>) {\n if (dto.user_id && dto.user_id !== identified) {\n identified = dto.user_id;\n track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });\n }\n\n // Once bound, the server's person key for the visitor is the user's id, so the setters are told\n // that rather than waiting for the server to say it.\n const identity = { ...dto, distinct_id: dto.user_id ?? null };\n config.thirdPartyUserSetters.forEach((setter) => {\n try {\n setter(identity);\n } catch (e: unknown) {\n // One third-party script does not get to stop the others.\n if (e instanceof Error) console.log(e.message);\n }\n });\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,iBAAiB;;AAG9B,IAAI;;;;;;;;;;AAWJ,SAAgB,WAAW,KAAqC;CAC9D,IAAI,IAAI,WAAW,IAAI,YAAY,YAAY;EAC7C,aAAa,IAAI;EACjB,MAAM,gBAAgB,EAAE,SAAS,IAAI,QAAQ,GAAG,EAAE,0BAA0B,MAAM,CAAC;CACrF;CAIA,MAAM,WAAW;EAAE,GAAG;EAAK,aAAa,IAAI,WAAW;CAAK;CAC5D,OAAO,sBAAsB,SAAS,WAAW;EAC/C,IAAI;GACF,OAAO,QAAQ;EACjB,SAAS,GAAY;GAEnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "11.1.0",
3
+ "version": "11.3.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",