@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.
- package/README.md +9 -5
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +3 -2
- package/dist/server/openai-conversions-api.cjs +2 -2
- package/dist/server/openai-conversions-api.cjs.map +1 -1
- package/dist/server/openai-conversions-api.d.cts.map +1 -1
- package/dist/server/openai-conversions-api.d.mts.map +1 -1
- package/dist/server/openai-conversions-api.mjs +3 -3
- package/dist/server/openai-conversions-api.mjs.map +1 -1
- package/dist/third-parties/ignored-events.cjs +7 -1
- package/dist/third-parties/ignored-events.cjs.map +1 -1
- package/dist/third-parties/ignored-events.d.cts.map +1 -1
- package/dist/third-parties/ignored-events.d.mts.map +1 -1
- package/dist/third-parties/ignored-events.mjs +7 -1
- package/dist/third-parties/ignored-events.mjs.map +1 -1
- package/dist/third-parties/microsoft-uet.cjs +2 -2
- package/dist/third-parties/microsoft-uet.cjs.map +1 -1
- package/dist/third-parties/microsoft-uet.mjs +1 -1
- package/dist/third-parties/microsoft-uet.mjs.map +1 -1
- package/dist/third-parties/openai-pixel.cjs +1 -0
- package/dist/third-parties/openai-pixel.cjs.map +1 -1
- package/dist/third-parties/openai-pixel.d.cts.map +1 -1
- package/dist/third-parties/openai-pixel.d.mts.map +1 -1
- package/dist/third-parties/openai-pixel.mjs +2 -1
- package/dist/third-parties/openai-pixel.mjs.map +1 -1
- package/dist/track/index.cjs +4 -4
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.mjs +1 -1
- package/dist/track/index.mjs.map +1 -1
- package/dist/track/oaiq.cjs +17 -0
- package/dist/track/oaiq.cjs.map +1 -1
- package/dist/track/oaiq.d.cts +8 -0
- package/dist/track/oaiq.d.cts.map +1 -1
- package/dist/track/oaiq.d.mts +8 -0
- package/dist/track/oaiq.d.mts.map +1 -1
- package/dist/track/oaiq.mjs +17 -1
- package/dist/track/oaiq.mjs.map +1 -1
- package/dist/visitor/id.cjs +25 -0
- package/dist/visitor/id.cjs.map +1 -0
- package/dist/visitor/id.d.cts +13 -0
- package/dist/visitor/id.d.cts.map +1 -0
- package/dist/visitor/id.d.mts +13 -0
- package/dist/visitor/id.d.mts.map +1 -0
- package/dist/visitor/id.mjs +24 -0
- package/dist/visitor/id.mjs.map +1 -0
- package/dist/visitor/index.cjs +24 -29
- package/dist/visitor/index.cjs.map +1 -1
- package/dist/visitor/index.d.cts +15 -9
- package/dist/visitor/index.d.cts.map +1 -1
- package/dist/visitor/index.d.mts +15 -9
- package/dist/visitor/index.d.mts.map +1 -1
- package/dist/visitor/index.mjs +23 -29
- package/dist/visitor/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/visitor/index.cjs
CHANGED
|
@@ -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
|
|
4
|
-
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
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
|
-
*
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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:
|
|
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":[
|
|
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"}
|
package/dist/visitor/index.d.cts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { visitorId } from "./id.cjs";
|
|
3
3
|
//#region src/visitor/index.d.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
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
|
-
*
|
|
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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa;;;;;;;;;;wBAcG,WAAW,KAAK,KAAK"}
|
package/dist/visitor/index.d.mts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { visitorId } from "./id.mjs";
|
|
3
3
|
//#region src/visitor/index.d.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
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
|
-
*
|
|
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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa;;;;;;;;;;wBAcG,WAAW,KAAK,KAAK"}
|
package/dist/visitor/index.mjs
CHANGED
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
import { config } from "../setup/index.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
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
|
-
*
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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:
|
|
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":[
|
|
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"}
|