@shware/analytics 15.0.0 → 16.0.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 +90 -37
- package/dist/native/fbsdk.cjs +45 -1
- package/dist/native/fbsdk.cjs.map +1 -1
- package/dist/native/fbsdk.d.cts +23 -1
- package/dist/native/fbsdk.d.cts.map +1 -1
- package/dist/native/fbsdk.d.mts +23 -1
- package/dist/native/fbsdk.d.mts.map +1 -1
- package/dist/native/fbsdk.mjs +44 -2
- package/dist/native/fbsdk.mjs.map +1 -1
- package/dist/native/firebase.cjs +27 -0
- package/dist/native/firebase.cjs.map +1 -1
- package/dist/native/firebase.d.cts +11 -0
- package/dist/native/firebase.d.cts.map +1 -1
- package/dist/native/firebase.d.mts +11 -0
- package/dist/native/firebase.d.mts.map +1 -1
- package/dist/native/firebase.mjs +27 -2
- package/dist/native/firebase.mjs.map +1 -1
- package/dist/next/index.cjs +10 -123
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +2 -31
- package/dist/next/index.d.cts.map +1 -1
- package/dist/next/index.d.mts +2 -31
- package/dist/next/index.d.mts.map +1 -1
- package/dist/next/index.mjs +10 -123
- package/dist/next/index.mjs.map +1 -1
- package/dist/react/index.cjs +45 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +15 -0
- package/dist/react/index.d.cts.map +1 -0
- package/dist/react/index.d.mts +15 -0
- package/dist/react/index.d.mts.map +1 -0
- package/dist/react/index.mjs +43 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/react/use-feature-flag.cjs +23 -0
- package/dist/react/use-feature-flag.cjs.map +1 -0
- package/dist/react/use-feature-flag.d.cts +10 -0
- package/dist/react/use-feature-flag.d.cts.map +1 -0
- package/dist/react/use-feature-flag.d.mts +10 -0
- package/dist/react/use-feature-flag.d.mts.map +1 -0
- package/dist/react/use-feature-flag.mjs +22 -0
- package/dist/react/use-feature-flag.mjs.map +1 -0
- package/dist/server/reddit-conversions-api.d.cts +1 -1
- package/dist/server/reddit-conversions-api.d.mts +1 -1
- package/dist/setup/index.cjs +4 -4
- package/dist/setup/index.cjs.map +1 -1
- package/dist/setup/index.d.cts +16 -6
- package/dist/setup/index.d.cts.map +1 -1
- package/dist/setup/index.d.mts +16 -6
- package/dist/setup/index.d.mts.map +1 -1
- package/dist/setup/index.mjs +4 -4
- package/dist/setup/index.mjs.map +1 -1
- package/dist/tanstack/index.cjs +0 -2
- package/dist/tanstack/index.d.cts +1 -2
- package/dist/tanstack/index.d.mts +1 -2
- package/dist/tanstack/index.mjs +1 -3
- package/dist/third-parties/analytics-props.cjs +28 -0
- package/dist/third-parties/analytics-props.cjs.map +1 -0
- package/dist/third-parties/analytics-props.d.cts +23 -0
- package/dist/third-parties/analytics-props.d.cts.map +1 -0
- package/dist/third-parties/analytics-props.d.mts +23 -0
- package/dist/third-parties/analytics-props.d.mts.map +1 -0
- package/dist/third-parties/analytics-props.mjs +26 -0
- package/dist/third-parties/analytics-props.mjs.map +1 -0
- package/dist/third-parties/google-analytics.cjs +32 -0
- package/dist/third-parties/google-analytics.cjs.map +1 -1
- package/dist/third-parties/google-analytics.d.cts +11 -1
- package/dist/third-parties/google-analytics.d.cts.map +1 -1
- package/dist/third-parties/google-analytics.d.mts +11 -1
- package/dist/third-parties/google-analytics.d.mts.map +1 -1
- package/dist/third-parties/google-analytics.mjs +32 -1
- package/dist/third-parties/google-analytics.mjs.map +1 -1
- package/dist/third-parties/index.cjs +16 -0
- package/dist/third-parties/index.d.cts +9 -7
- package/dist/third-parties/index.d.mts +9 -7
- package/dist/third-parties/index.mjs +9 -7
- package/dist/third-parties/integration.cjs +39 -0
- package/dist/third-parties/integration.cjs.map +1 -0
- package/dist/third-parties/integration.d.cts +57 -0
- package/dist/third-parties/integration.d.cts.map +1 -0
- package/dist/third-parties/integration.d.mts +57 -0
- package/dist/third-parties/integration.d.mts.map +1 -0
- package/dist/third-parties/integration.mjs +37 -0
- package/dist/third-parties/integration.mjs.map +1 -0
- package/dist/third-parties/linkedin-insight-tag.cjs +33 -0
- package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.cts +12 -8
- package/dist/third-parties/linkedin-insight-tag.d.cts.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.mts +12 -8
- package/dist/third-parties/linkedin-insight-tag.d.mts.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.mjs +33 -1
- package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -1
- package/dist/third-parties/meta-pixel.cjs +34 -0
- package/dist/third-parties/meta-pixel.cjs.map +1 -1
- package/dist/third-parties/meta-pixel.d.cts +5 -0
- package/dist/third-parties/meta-pixel.d.cts.map +1 -1
- package/dist/third-parties/meta-pixel.d.mts +5 -0
- package/dist/third-parties/meta-pixel.d.mts.map +1 -1
- package/dist/third-parties/meta-pixel.mjs +34 -1
- package/dist/third-parties/meta-pixel.mjs.map +1 -1
- package/dist/third-parties/microsoft-uet.cjs +49 -0
- package/dist/third-parties/microsoft-uet.cjs.map +1 -1
- package/dist/third-parties/microsoft-uet.d.cts +29 -0
- package/dist/third-parties/microsoft-uet.d.cts.map +1 -1
- package/dist/third-parties/microsoft-uet.d.mts +29 -0
- package/dist/third-parties/microsoft-uet.d.mts.map +1 -1
- package/dist/third-parties/microsoft-uet.mjs +48 -1
- package/dist/third-parties/microsoft-uet.mjs.map +1 -1
- package/dist/third-parties/openai-pixel.cjs +31 -0
- package/dist/third-parties/openai-pixel.cjs.map +1 -1
- package/dist/third-parties/openai-pixel.d.cts +5 -0
- package/dist/third-parties/openai-pixel.d.cts.map +1 -1
- package/dist/third-parties/openai-pixel.d.mts +5 -0
- package/dist/third-parties/openai-pixel.d.mts.map +1 -1
- package/dist/third-parties/openai-pixel.mjs +31 -1
- package/dist/third-parties/openai-pixel.mjs.map +1 -1
- package/dist/third-parties/posthog.cjs +97 -4
- package/dist/third-parties/posthog.cjs.map +1 -1
- package/dist/third-parties/posthog.d.cts +56 -1
- package/dist/third-parties/posthog.d.cts.map +1 -1
- package/dist/third-parties/posthog.d.mts +56 -1
- package/dist/third-parties/posthog.d.mts.map +1 -1
- package/dist/third-parties/posthog.mjs +91 -2
- package/dist/third-parties/posthog.mjs.map +1 -1
- package/dist/third-parties/reddit-pixel.cjs +32 -0
- package/dist/third-parties/reddit-pixel.cjs.map +1 -1
- package/dist/third-parties/reddit-pixel.d.cts +5 -0
- package/dist/third-parties/reddit-pixel.d.cts.map +1 -1
- package/dist/third-parties/reddit-pixel.d.mts +5 -0
- package/dist/third-parties/reddit-pixel.d.mts.map +1 -1
- package/dist/third-parties/reddit-pixel.mjs +32 -1
- package/dist/third-parties/reddit-pixel.mjs.map +1 -1
- package/dist/track/fbq.cjs +1 -1
- package/dist/track/fbq.cjs.map +1 -1
- package/dist/track/fbq.mjs +1 -1
- package/dist/track/fbq.mjs.map +1 -1
- package/dist/track/index.cjs +7 -7
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.d.cts.map +1 -1
- package/dist/track/index.d.mts.map +1 -1
- package/dist/track/index.mjs +7 -7
- package/dist/track/index.mjs.map +1 -1
- package/dist/visitor/index.cjs +36 -20
- package/dist/visitor/index.cjs.map +1 -1
- package/dist/visitor/index.d.cts +9 -6
- package/dist/visitor/index.d.cts.map +1 -1
- package/dist/visitor/index.d.mts +9 -6
- package/dist/visitor/index.d.mts.map +1 -1
- package/dist/visitor/index.mjs +36 -20
- package/dist/visitor/index.mjs.map +1 -1
- package/package.json +11 -24
- package/dist/react-router/index.cjs +0 -160
- package/dist/react-router/index.cjs.map +0 -1
- package/dist/react-router/index.d.cts +0 -22
- package/dist/react-router/index.d.cts.map +0 -1
- package/dist/react-router/index.d.mts +0 -22
- package/dist/react-router/index.d.mts.map +0 -1
- package/dist/react-router/index.mjs +0 -159
- package/dist/react-router/index.mjs.map +0 -1
- package/dist/tanstack/analytics.cjs +0 -184
- package/dist/tanstack/analytics.cjs.map +0 -1
- package/dist/tanstack/analytics.d.cts +0 -33
- package/dist/tanstack/analytics.d.cts.map +0 -1
- package/dist/tanstack/analytics.d.mts +0 -33
- package/dist/tanstack/analytics.d.mts.map +0 -1
- package/dist/tanstack/analytics.mjs +0 -183
- package/dist/tanstack/analytics.mjs.map +0 -1
package/dist/visitor/index.cjs
CHANGED
|
@@ -14,14 +14,18 @@ const IDENTIFY_EVENT = "identify";
|
|
|
14
14
|
* The visitor and user this page last identified, as `<visitor>:<user>`: identify once per binding
|
|
15
15
|
* per page, not per call. The visitor is part of it because the storage is shared: another tab's
|
|
16
16
|
* `reset()` replaces the visitor under this page, and the same user here must then bind the new
|
|
17
|
-
* one too.
|
|
17
|
+
* one too.
|
|
18
|
+
*
|
|
19
|
+
* `undefined` until this page identifies anyone; `null` once it has signed out (`reset()`), so the
|
|
20
|
+
* same user signing back in is identified again, and a later `reset()` here knows it has nothing
|
|
21
|
+
* left to sign out — the device's identity, if any, is someone this page has not identified.
|
|
18
22
|
*/
|
|
19
23
|
let identified;
|
|
20
|
-
/** Hands the user to every
|
|
24
|
+
/** Hands the user to every integration's user setter; one that throws does not stop the others. */
|
|
21
25
|
function setUsers(user) {
|
|
22
|
-
require_setup_index.config.
|
|
26
|
+
require_setup_index.config.integrations.forEach(({ setUser }) => {
|
|
23
27
|
try {
|
|
24
|
-
|
|
28
|
+
setUser?.(user);
|
|
25
29
|
} catch (e) {
|
|
26
30
|
if (e instanceof Error) console.log(e.message);
|
|
27
31
|
}
|
|
@@ -45,7 +49,10 @@ function identify(userId, userData) {
|
|
|
45
49
|
let visitor = "";
|
|
46
50
|
try {
|
|
47
51
|
const previous = require_setup_index.config.storage.getItem(require_constants_storage.keys.user_id);
|
|
48
|
-
if (previous && previous !== userId)
|
|
52
|
+
if (previous && previous !== userId) {
|
|
53
|
+
startOver();
|
|
54
|
+
setUsers({});
|
|
55
|
+
}
|
|
49
56
|
require_setup_index.config.storage.setItem(require_constants_storage.keys.user_id, userId);
|
|
50
57
|
visitor = require_visitor_id.visitorId();
|
|
51
58
|
} catch (e) {
|
|
@@ -75,29 +82,38 @@ function identify(userId, userData) {
|
|
|
75
82
|
*
|
|
76
83
|
* The device id and the first visit or first open stay: they describe the device, not the person.
|
|
77
84
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
85
|
+
* Only the sign-out this page knows of: the session and visitor are replaced while the device's
|
|
86
|
+
* identity (`keys.user_id` and the visitor, shared by every tab) is still the one this page last
|
|
87
|
+
* identified, or the page has neither identified nor signed out anyone (a host that identifies at
|
|
88
|
+
* sign-in only, on a page loaded since). Every tab of a site sees a sign-out and calls this,
|
|
89
|
+
* some of them late — a tab frozen in the background handles it on resuming, after another tab
|
|
90
|
+
* may have signed out and in again. A call that finds no user, or someone else's binding, is
|
|
91
|
+
* stale: replacing that would cut the new anonymous visitor off from the next sign-in, or end the
|
|
92
|
+
* next user's session and leave their pages on a visitor nobody identified. It only clears this
|
|
93
|
+
* page: its setters are still told, since GA holds the user per page.
|
|
84
94
|
*
|
|
85
95
|
* Synchronous and never throws: sign-out must not fail on analytics.
|
|
86
96
|
*/
|
|
87
97
|
function reset() {
|
|
88
|
-
let
|
|
98
|
+
let current = false;
|
|
89
99
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
require_visitor_id.newVisitorId();
|
|
94
|
-
require_setup_index.config.storage.setItem(require_constants_storage.keys.user_id, "");
|
|
95
|
-
}
|
|
100
|
+
const user = require_setup_index.config.storage.getItem(require_constants_storage.keys.user_id);
|
|
101
|
+
current = !!user && (identified === void 0 || identified === `${require_visitor_id.visitorId()}:${user}`);
|
|
102
|
+
if (current) startOver();
|
|
96
103
|
} catch (e) {
|
|
97
104
|
if (e instanceof Error) console.log(e.message);
|
|
98
105
|
}
|
|
99
|
-
if (
|
|
100
|
-
identified =
|
|
106
|
+
if (current || identified) setUsers({});
|
|
107
|
+
identified = null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Ends the device's session and starts a new visitor with no user: `reset()` for the sign-out it
|
|
111
|
+
* knows of, `identify` for a user signing in over another.
|
|
112
|
+
*/
|
|
113
|
+
function startOver() {
|
|
114
|
+
require_track_index.endSession();
|
|
115
|
+
require_visitor_id.newVisitorId();
|
|
116
|
+
require_setup_index.config.storage.setItem(require_constants_storage.keys.user_id, "");
|
|
101
117
|
}
|
|
102
118
|
exports.IDENTIFY_EVENT = IDENTIFY_EVENT;
|
|
103
119
|
exports.identify = identify;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["config","keys","visitorId"],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import { keys } from '../constants/storage';\nimport { config } from '../setup/index';\nimport { endSession, track } from '../track/index';\nimport type { UserProvidedData } from '../track/types';\nimport { newVisitorId, visitorId } from './id';\nimport type { ThirdPartyUserSetter } from './types';\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/**\n * The visitor and user this page last identified, as `<visitor>:<user>`: identify once per binding\n * per page, not per call. The visitor is part of it because the storage is shared: another tab's\n * `reset()` replaces the visitor under this page, and the same user here must then bind the new\n * one too
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["config","keys","visitorId"],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import { keys } from '../constants/storage';\nimport { config } from '../setup/index';\nimport { endSession, track } from '../track/index';\nimport type { UserProvidedData } from '../track/types';\nimport { newVisitorId, visitorId } from './id';\nimport type { ThirdPartyUserSetter } from './types';\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/**\n * The visitor and user this page last identified, as `<visitor>:<user>`: identify once per binding\n * per page, not per call. The visitor is part of it because the storage is shared: another tab's\n * `reset()` replaces the visitor under this page, and the same user here must then bind the new\n * one too.\n *\n * `undefined` until this page identifies anyone; `null` once it has signed out (`reset()`), so the\n * same user signing back in is identified again, and a later `reset()` here knows it has nothing\n * left to sign out — the device's identity, if any, is someone this page has not identified.\n */\nlet identified: string | null | undefined;\n\n/** Hands the user to every integration's user setter; one that throws does not stop the others. */\nfunction setUsers(user: Parameters<ThirdPartyUserSetter>[0]) {\n config.integrations.forEach(({ setUser }) => {\n try {\n setUser?.(user);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n });\n}\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; `userData` is handed to the setters\n * only, never stored with the event.\n *\n * The visitor's sessions so far — those before the sign-in included — become this user's. So a\n * different user than the one last identified on this device (an expired session, a sign-out the\n * host never reported) is `reset()` first: the previous user's visitor stays theirs, and this one\n * starts on a new visitor.\n *\n * Synchronous and never throws: sign-in must not fail on analytics.\n */\nexport function identify(userId: string, userData?: UserProvidedData) {\n let visitor = '';\n try {\n const previous = config.storage.getItem(keys.user_id);\n if (previous && previous !== userId) {\n // Another user is on the device: start over whatever this page last identified.\n startOver();\n setUsers({});\n }\n config.storage.setItem(keys.user_id, userId);\n visitor = visitorId();\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n\n const binding = `${visitor}:${userId}`;\n if (binding !== identified) {\n identified = binding;\n track(IDENTIFY_EVENT, { user_id: userId }, { enableThirdPartyTracking: false });\n }\n\n setUsers({ user_id: userId, user_data: userData });\n}\n\n/**\n * Signs the visitor out, as PostHog's `reset()` does: call it on sign-out, after\n * `track('logout')`, so that event still belongs to the user leaving.\n *\n * - The current session ends: what it accrued goes out as a `user_engagement`\n * (`trigger: 'reset'`), as when the page is closed, and the queue is sent under the visitor\n * and session its events happened in.\n * - A new visitor starts, and the next event opens a new session on it. Everything until the next\n * sign-in is anonymous, and becomes whoever's signs in next; the visitor that is left stays the\n * previous user's, with its history.\n * - The third-party setters drop the user (PostHog resets its identity, GA clears its user_id).\n *\n * The device id and the first visit or first open stay: they describe the device, not the person.\n *\n * Only the sign-out this page knows of: the session and visitor are replaced while the device's\n * identity (`keys.user_id` and the visitor, shared by every tab) is still the one this page last\n * identified, or the page has neither identified nor signed out anyone (a host that identifies at\n * sign-in only, on a page loaded since). Every tab of a site sees a sign-out and calls this,\n * some of them late — a tab frozen in the background handles it on resuming, after another tab\n * may have signed out and in again. A call that finds no user, or someone else's binding, is\n * stale: replacing that would cut the new anonymous visitor off from the next sign-in, or end the\n * next user's session and leave their pages on a visitor nobody identified. It only clears this\n * page: its setters are still told, since GA holds the user per page.\n *\n * Synchronous and never throws: sign-out must not fail on analytics.\n */\nexport function reset() {\n let current = false;\n try {\n const user = config.storage.getItem(keys.user_id);\n current = !!user && (identified === undefined || identified === `${visitorId()}:${user}`);\n if (current) startOver();\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n if (current || identified) setUsers({});\n identified = null;\n}\n\n/**\n * Ends the device's session and starts a new visitor with no user: `reset()` for the sign-out it\n * knows of, `identify` for a user signing in over another.\n */\nfunction startOver() {\n endSession();\n newVisitorId();\n config.storage.setItem(keys.user_id, '');\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,iBAAiB;;;;;;;;;;;AAY9B,IAAI;;AAGJ,SAAS,SAAS,MAA2C;CAC3D,oBAAA,OAAO,aAAa,SAAS,EAAE,cAAc;EAC3C,IAAI;GACF,UAAU,IAAI;EAChB,SAAS,GAAY;GACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;AACH;;;;;;;;;;;;;;;AAgBA,SAAgB,SAAS,QAAgB,UAA6B;CACpE,IAAI,UAAU;CACd,IAAI;EACF,MAAM,WAAWA,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,OAAO;EACpD,IAAI,YAAY,aAAa,QAAQ;GAEnC,UAAU;GACV,SAAS,CAAC,CAAC;EACb;EACA,oBAAA,OAAO,QAAQ,QAAQA,0BAAAA,KAAK,SAAS,MAAM;EAC3C,UAAUC,mBAAAA,UAAU;CACtB,SAAS,GAAY;EACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;CAC/C;CAEA,MAAM,UAAU,GAAG,QAAQ,GAAG;CAC9B,IAAI,YAAY,YAAY;EAC1B,aAAa;EACb,oBAAA,MAAM,gBAAgB,EAAE,SAAS,OAAO,GAAG,EAAE,0BAA0B,MAAM,CAAC;CAChF;CAEA,SAAS;EAAE,SAAS;EAAQ,WAAW;CAAS,CAAC;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,QAAQ;CACtB,IAAI,UAAU;CACd,IAAI;EACF,MAAM,OAAOF,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,OAAO;EAChD,UAAU,CAAC,CAAC,SAAS,eAAe,KAAA,KAAa,eAAe,GAAGC,mBAAAA,UAAU,EAAE,GAAG;EAClF,IAAI,SAAS,UAAU;CACzB,SAAS,GAAY;EACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;CAC/C;CACA,IAAI,WAAW,YAAY,SAAS,CAAC,CAAC;CACtC,aAAa;AACf;;;;;AAMA,SAAS,YAAY;CACnB,oBAAA,WAAW;CACX,mBAAA,aAAa;CACb,oBAAA,OAAO,QAAQ,QAAQD,0BAAAA,KAAK,SAAS,EAAE;AACzC"}
|
package/dist/visitor/index.d.cts
CHANGED
|
@@ -35,12 +35,15 @@ export declare function identify(userId: string, userData?: UserProvidedData): v
|
|
|
35
35
|
*
|
|
36
36
|
* The device id and the first visit or first open stay: they describe the device, not the person.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
38
|
+
* Only the sign-out this page knows of: the session and visitor are replaced while the device's
|
|
39
|
+
* identity (`keys.user_id` and the visitor, shared by every tab) is still the one this page last
|
|
40
|
+
* identified, or the page has neither identified nor signed out anyone (a host that identifies at
|
|
41
|
+
* sign-in only, on a page loaded since). Every tab of a site sees a sign-out and calls this,
|
|
42
|
+
* some of them late — a tab frozen in the background handles it on resuming, after another tab
|
|
43
|
+
* may have signed out and in again. A call that finds no user, or someone else's binding, is
|
|
44
|
+
* stale: replacing that would cut the new anonymous visitor off from the next sign-in, or end the
|
|
45
|
+
* next user's session and leave their pages on a visitor nobody identified. It only clears this
|
|
46
|
+
* page: its setters are still told, since GA holds the user per page.
|
|
44
47
|
*
|
|
45
48
|
* Synchronous and never throws: sign-out must not fail on analytics.
|
|
46
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;qBAca;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;qBAca;;;;;;;;;;;;;;;wBAuCG,SAAS,gBAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkDpC"}
|
package/dist/visitor/index.d.mts
CHANGED
|
@@ -35,12 +35,15 @@ export declare function identify(userId: string, userData?: UserProvidedData): v
|
|
|
35
35
|
*
|
|
36
36
|
* The device id and the first visit or first open stay: they describe the device, not the person.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
38
|
+
* Only the sign-out this page knows of: the session and visitor are replaced while the device's
|
|
39
|
+
* identity (`keys.user_id` and the visitor, shared by every tab) is still the one this page last
|
|
40
|
+
* identified, or the page has neither identified nor signed out anyone (a host that identifies at
|
|
41
|
+
* sign-in only, on a page loaded since). Every tab of a site sees a sign-out and calls this,
|
|
42
|
+
* some of them late — a tab frozen in the background handles it on resuming, after another tab
|
|
43
|
+
* may have signed out and in again. A call that finds no user, or someone else's binding, is
|
|
44
|
+
* stale: replacing that would cut the new anonymous visitor off from the next sign-in, or end the
|
|
45
|
+
* next user's session and leave their pages on a visitor nobody identified. It only clears this
|
|
46
|
+
* page: its setters are still told, since GA holds the user per page.
|
|
44
47
|
*
|
|
45
48
|
* Synchronous and never throws: sign-out must not fail on analytics.
|
|
46
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;qBAca;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;qBAca;;;;;;;;;;;;;;;wBAuCG,SAAS,gBAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkDpC"}
|
package/dist/visitor/index.mjs
CHANGED
|
@@ -13,14 +13,18 @@ const IDENTIFY_EVENT = "identify";
|
|
|
13
13
|
* The visitor and user this page last identified, as `<visitor>:<user>`: identify once per binding
|
|
14
14
|
* per page, not per call. The visitor is part of it because the storage is shared: another tab's
|
|
15
15
|
* `reset()` replaces the visitor under this page, and the same user here must then bind the new
|
|
16
|
-
* one too.
|
|
16
|
+
* one too.
|
|
17
|
+
*
|
|
18
|
+
* `undefined` until this page identifies anyone; `null` once it has signed out (`reset()`), so the
|
|
19
|
+
* same user signing back in is identified again, and a later `reset()` here knows it has nothing
|
|
20
|
+
* left to sign out — the device's identity, if any, is someone this page has not identified.
|
|
17
21
|
*/
|
|
18
22
|
let identified;
|
|
19
|
-
/** Hands the user to every
|
|
23
|
+
/** Hands the user to every integration's user setter; one that throws does not stop the others. */
|
|
20
24
|
function setUsers(user) {
|
|
21
|
-
config.
|
|
25
|
+
config.integrations.forEach(({ setUser }) => {
|
|
22
26
|
try {
|
|
23
|
-
|
|
27
|
+
setUser?.(user);
|
|
24
28
|
} catch (e) {
|
|
25
29
|
if (e instanceof Error) console.log(e.message);
|
|
26
30
|
}
|
|
@@ -44,7 +48,10 @@ function identify(userId, userData) {
|
|
|
44
48
|
let visitor = "";
|
|
45
49
|
try {
|
|
46
50
|
const previous = config.storage.getItem(keys.user_id);
|
|
47
|
-
if (previous && previous !== userId)
|
|
51
|
+
if (previous && previous !== userId) {
|
|
52
|
+
startOver();
|
|
53
|
+
setUsers({});
|
|
54
|
+
}
|
|
48
55
|
config.storage.setItem(keys.user_id, userId);
|
|
49
56
|
visitor = visitorId();
|
|
50
57
|
} catch (e) {
|
|
@@ -74,29 +81,38 @@ function identify(userId, userData) {
|
|
|
74
81
|
*
|
|
75
82
|
* The device id and the first visit or first open stay: they describe the device, not the person.
|
|
76
83
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
84
|
+
* Only the sign-out this page knows of: the session and visitor are replaced while the device's
|
|
85
|
+
* identity (`keys.user_id` and the visitor, shared by every tab) is still the one this page last
|
|
86
|
+
* identified, or the page has neither identified nor signed out anyone (a host that identifies at
|
|
87
|
+
* sign-in only, on a page loaded since). Every tab of a site sees a sign-out and calls this,
|
|
88
|
+
* some of them late — a tab frozen in the background handles it on resuming, after another tab
|
|
89
|
+
* may have signed out and in again. A call that finds no user, or someone else's binding, is
|
|
90
|
+
* stale: replacing that would cut the new anonymous visitor off from the next sign-in, or end the
|
|
91
|
+
* next user's session and leave their pages on a visitor nobody identified. It only clears this
|
|
92
|
+
* page: its setters are still told, since GA holds the user per page.
|
|
83
93
|
*
|
|
84
94
|
* Synchronous and never throws: sign-out must not fail on analytics.
|
|
85
95
|
*/
|
|
86
96
|
function reset() {
|
|
87
|
-
let
|
|
97
|
+
let current = false;
|
|
88
98
|
try {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
newVisitorId();
|
|
93
|
-
config.storage.setItem(keys.user_id, "");
|
|
94
|
-
}
|
|
99
|
+
const user = config.storage.getItem(keys.user_id);
|
|
100
|
+
current = !!user && (identified === void 0 || identified === `${visitorId()}:${user}`);
|
|
101
|
+
if (current) startOver();
|
|
95
102
|
} catch (e) {
|
|
96
103
|
if (e instanceof Error) console.log(e.message);
|
|
97
104
|
}
|
|
98
|
-
if (
|
|
99
|
-
identified =
|
|
105
|
+
if (current || identified) setUsers({});
|
|
106
|
+
identified = null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Ends the device's session and starts a new visitor with no user: `reset()` for the sign-out it
|
|
110
|
+
* knows of, `identify` for a user signing in over another.
|
|
111
|
+
*/
|
|
112
|
+
function startOver() {
|
|
113
|
+
endSession();
|
|
114
|
+
newVisitorId();
|
|
115
|
+
config.storage.setItem(keys.user_id, "");
|
|
100
116
|
}
|
|
101
117
|
export { IDENTIFY_EVENT, identify, reset, visitorId };
|
|
102
118
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import { keys } from '../constants/storage';\nimport { config } from '../setup/index';\nimport { endSession, track } from '../track/index';\nimport type { UserProvidedData } from '../track/types';\nimport { newVisitorId, visitorId } from './id';\nimport type { ThirdPartyUserSetter } from './types';\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/**\n * The visitor and user this page last identified, as `<visitor>:<user>`: identify once per binding\n * per page, not per call. The visitor is part of it because the storage is shared: another tab's\n * `reset()` replaces the visitor under this page, and the same user here must then bind the new\n * one too
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import { keys } from '../constants/storage';\nimport { config } from '../setup/index';\nimport { endSession, track } from '../track/index';\nimport type { UserProvidedData } from '../track/types';\nimport { newVisitorId, visitorId } from './id';\nimport type { ThirdPartyUserSetter } from './types';\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/**\n * The visitor and user this page last identified, as `<visitor>:<user>`: identify once per binding\n * per page, not per call. The visitor is part of it because the storage is shared: another tab's\n * `reset()` replaces the visitor under this page, and the same user here must then bind the new\n * one too.\n *\n * `undefined` until this page identifies anyone; `null` once it has signed out (`reset()`), so the\n * same user signing back in is identified again, and a later `reset()` here knows it has nothing\n * left to sign out — the device's identity, if any, is someone this page has not identified.\n */\nlet identified: string | null | undefined;\n\n/** Hands the user to every integration's user setter; one that throws does not stop the others. */\nfunction setUsers(user: Parameters<ThirdPartyUserSetter>[0]) {\n config.integrations.forEach(({ setUser }) => {\n try {\n setUser?.(user);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n });\n}\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; `userData` is handed to the setters\n * only, never stored with the event.\n *\n * The visitor's sessions so far — those before the sign-in included — become this user's. So a\n * different user than the one last identified on this device (an expired session, a sign-out the\n * host never reported) is `reset()` first: the previous user's visitor stays theirs, and this one\n * starts on a new visitor.\n *\n * Synchronous and never throws: sign-in must not fail on analytics.\n */\nexport function identify(userId: string, userData?: UserProvidedData) {\n let visitor = '';\n try {\n const previous = config.storage.getItem(keys.user_id);\n if (previous && previous !== userId) {\n // Another user is on the device: start over whatever this page last identified.\n startOver();\n setUsers({});\n }\n config.storage.setItem(keys.user_id, userId);\n visitor = visitorId();\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n\n const binding = `${visitor}:${userId}`;\n if (binding !== identified) {\n identified = binding;\n track(IDENTIFY_EVENT, { user_id: userId }, { enableThirdPartyTracking: false });\n }\n\n setUsers({ user_id: userId, user_data: userData });\n}\n\n/**\n * Signs the visitor out, as PostHog's `reset()` does: call it on sign-out, after\n * `track('logout')`, so that event still belongs to the user leaving.\n *\n * - The current session ends: what it accrued goes out as a `user_engagement`\n * (`trigger: 'reset'`), as when the page is closed, and the queue is sent under the visitor\n * and session its events happened in.\n * - A new visitor starts, and the next event opens a new session on it. Everything until the next\n * sign-in is anonymous, and becomes whoever's signs in next; the visitor that is left stays the\n * previous user's, with its history.\n * - The third-party setters drop the user (PostHog resets its identity, GA clears its user_id).\n *\n * The device id and the first visit or first open stay: they describe the device, not the person.\n *\n * Only the sign-out this page knows of: the session and visitor are replaced while the device's\n * identity (`keys.user_id` and the visitor, shared by every tab) is still the one this page last\n * identified, or the page has neither identified nor signed out anyone (a host that identifies at\n * sign-in only, on a page loaded since). Every tab of a site sees a sign-out and calls this,\n * some of them late — a tab frozen in the background handles it on resuming, after another tab\n * may have signed out and in again. A call that finds no user, or someone else's binding, is\n * stale: replacing that would cut the new anonymous visitor off from the next sign-in, or end the\n * next user's session and leave their pages on a visitor nobody identified. It only clears this\n * page: its setters are still told, since GA holds the user per page.\n *\n * Synchronous and never throws: sign-out must not fail on analytics.\n */\nexport function reset() {\n let current = false;\n try {\n const user = config.storage.getItem(keys.user_id);\n current = !!user && (identified === undefined || identified === `${visitorId()}:${user}`);\n if (current) startOver();\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n if (current || identified) setUsers({});\n identified = null;\n}\n\n/**\n * Ends the device's session and starts a new visitor with no user: `reset()` for the sign-out it\n * knows of, `identify` for a user signing in over another.\n */\nfunction startOver() {\n endSession();\n newVisitorId();\n config.storage.setItem(keys.user_id, '');\n}\n"],"mappings":";;;;;;;;;;AAcA,MAAa,iBAAiB;;;;;;;;;;;AAY9B,IAAI;;AAGJ,SAAS,SAAS,MAA2C;CAC3D,OAAO,aAAa,SAAS,EAAE,cAAc;EAC3C,IAAI;GACF,UAAU,IAAI;EAChB,SAAS,GAAY;GACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;AACH;;;;;;;;;;;;;;;AAgBA,SAAgB,SAAS,QAAgB,UAA6B;CACpE,IAAI,UAAU;CACd,IAAI;EACF,MAAM,WAAW,OAAO,QAAQ,QAAQ,KAAK,OAAO;EACpD,IAAI,YAAY,aAAa,QAAQ;GAEnC,UAAU;GACV,SAAS,CAAC,CAAC;EACb;EACA,OAAO,QAAQ,QAAQ,KAAK,SAAS,MAAM;EAC3C,UAAU,UAAU;CACtB,SAAS,GAAY;EACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;CAC/C;CAEA,MAAM,UAAU,GAAG,QAAQ,GAAG;CAC9B,IAAI,YAAY,YAAY;EAC1B,aAAa;EACb,MAAM,gBAAgB,EAAE,SAAS,OAAO,GAAG,EAAE,0BAA0B,MAAM,CAAC;CAChF;CAEA,SAAS;EAAE,SAAS;EAAQ,WAAW;CAAS,CAAC;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,QAAQ;CACtB,IAAI,UAAU;CACd,IAAI;EACF,MAAM,OAAO,OAAO,QAAQ,QAAQ,KAAK,OAAO;EAChD,UAAU,CAAC,CAAC,SAAS,eAAe,KAAA,KAAa,eAAe,GAAG,UAAU,EAAE,GAAG;EAClF,IAAI,SAAS,UAAU;CACzB,SAAS,GAAY;EACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;CAC/C;CACA,IAAI,WAAW,YAAY,SAAS,CAAC,CAAC;CACtC,aAAa;AACf;;;;;AAMA,SAAS,YAAY;CACnB,WAAW;CACX,aAAa;CACb,OAAO,QAAQ,QAAQ,KAAK,SAAS,EAAE;AACzC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/analytics",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -91,14 +91,14 @@
|
|
|
91
91
|
"default": "./dist/next/index.cjs"
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
|
-
"./react
|
|
94
|
+
"./react": {
|
|
95
95
|
"import": {
|
|
96
|
-
"types": "./dist/react
|
|
97
|
-
"default": "./dist/react
|
|
96
|
+
"types": "./dist/react/index.d.mts",
|
|
97
|
+
"default": "./dist/react/index.mjs"
|
|
98
98
|
},
|
|
99
99
|
"require": {
|
|
100
|
-
"types": "./dist/react
|
|
101
|
-
"default": "./dist/react
|
|
100
|
+
"types": "./dist/react/index.d.cts",
|
|
101
|
+
"default": "./dist/react/index.cjs"
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"./tanstack": {
|
|
@@ -121,16 +121,6 @@
|
|
|
121
121
|
"default": "./dist/third-parties/index.cjs"
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
|
-
"./third-parties/posthog": {
|
|
125
|
-
"import": {
|
|
126
|
-
"types": "./dist/third-parties/posthog.d.mts",
|
|
127
|
-
"default": "./dist/third-parties/posthog.mjs"
|
|
128
|
-
},
|
|
129
|
-
"require": {
|
|
130
|
-
"types": "./dist/third-parties/posthog.d.cts",
|
|
131
|
-
"default": "./dist/third-parties/posthog.cjs"
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
124
|
"./server": {
|
|
135
125
|
"import": {
|
|
136
126
|
"types": "./dist/server/index.d.mts",
|
|
@@ -170,6 +160,7 @@
|
|
|
170
160
|
"@types/facebook-nodejs-business-sdk": "^24.0.0",
|
|
171
161
|
"@types/node": "^26.6.5",
|
|
172
162
|
"@types/react": "^19.3.0",
|
|
163
|
+
"@types/react-dom": "^19.3.0",
|
|
173
164
|
"@vitest/coverage-v8": "^5.0.5",
|
|
174
165
|
"babel-plugin-react-compiler": "1.0.0",
|
|
175
166
|
"bowser": "^2.14.1",
|
|
@@ -181,7 +172,6 @@
|
|
|
181
172
|
},
|
|
182
173
|
"peerDependencies": {
|
|
183
174
|
"@react-native-firebase/analytics": "^26.4.1",
|
|
184
|
-
"@tanstack/react-router": "^1.170.46",
|
|
185
175
|
"@tanstack/react-start": "^1.169.4",
|
|
186
176
|
"expo-application": "^57.0.3 || ^58.0.0",
|
|
187
177
|
"expo-clipboard": "^57.0.2 || ^58.0.0",
|
|
@@ -194,18 +184,15 @@
|
|
|
194
184
|
"next": "^16.4.3",
|
|
195
185
|
"posthog-js": "^1.438.21",
|
|
196
186
|
"react": "^19.3.1",
|
|
187
|
+
"react-dom": "^19.3.1",
|
|
197
188
|
"react-native": "^0.87.1 || ^0.88.0",
|
|
198
189
|
"react-native-fbsdk-next": "^13.4.3",
|
|
199
|
-
"react-router": "^8.5.0",
|
|
200
190
|
"zod": "^4.6.5"
|
|
201
191
|
},
|
|
202
192
|
"peerDependenciesMeta": {
|
|
203
193
|
"@react-native-firebase/analytics": {
|
|
204
194
|
"optional": true
|
|
205
195
|
},
|
|
206
|
-
"@tanstack/react-router": {
|
|
207
|
-
"optional": true
|
|
208
|
-
},
|
|
209
196
|
"@tanstack/react-start": {
|
|
210
197
|
"optional": true
|
|
211
198
|
},
|
|
@@ -242,13 +229,13 @@
|
|
|
242
229
|
"react": {
|
|
243
230
|
"optional": true
|
|
244
231
|
},
|
|
245
|
-
"react-
|
|
232
|
+
"react-dom": {
|
|
246
233
|
"optional": true
|
|
247
234
|
},
|
|
248
|
-
"react-native
|
|
235
|
+
"react-native": {
|
|
249
236
|
"optional": true
|
|
250
237
|
},
|
|
251
|
-
"react-
|
|
238
|
+
"react-native-fbsdk-next": {
|
|
252
239
|
"optional": true
|
|
253
240
|
}
|
|
254
241
|
},
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_track_index = require("../track/index.cjs");
|
|
3
|
-
const require_hooks_use_outbound_click_analytics = require("../hooks/use-outbound-click-analytics.cjs");
|
|
4
|
-
const require_hooks_use_report_web_vitals = require("../hooks/use-report-web-vitals.cjs");
|
|
5
|
-
const require_hooks_use_uet_id_sync = require("../hooks/use-uet-id-sync.cjs");
|
|
6
|
-
const require_hooks_use_web_analytics = require("../hooks/use-web-analytics.cjs");
|
|
7
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
-
let react_router = require("react-router");
|
|
9
|
-
// src/react-router/index.tsx
|
|
10
|
-
function Analytics({ gaId, gaSrc, nonce, debugMode, metaPixelId, redditPixelId, linkedInPartnerId, uetTagId, uetCustomerId, hotjarId, facebookAppId, reportWebVitals = true }) {
|
|
11
|
-
const { pathname, search } = (0, react_router.useLocation)();
|
|
12
|
-
require_hooks_use_web_analytics.useWebAnalytics(pathname, search);
|
|
13
|
-
require_hooks_use_outbound_click_analytics.useOutboundClickAnalytics();
|
|
14
|
-
require_hooks_use_uet_id_sync.useUETIdSync(uetCustomerId);
|
|
15
|
-
require_hooks_use_report_web_vitals.useReportWebVitals((metric) => {
|
|
16
|
-
if (!reportWebVitals) return;
|
|
17
|
-
const properties = {
|
|
18
|
-
value: metric.delta,
|
|
19
|
-
metric_id: metric.id,
|
|
20
|
-
metric_value: metric.value,
|
|
21
|
-
metric_delta: metric.delta,
|
|
22
|
-
metric_rating: metric.rating,
|
|
23
|
-
metric_navigation_type: metric.navigationType,
|
|
24
|
-
non_interaction: true
|
|
25
|
-
};
|
|
26
|
-
require_track_index.track(metric.name, properties);
|
|
27
|
-
});
|
|
28
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
29
|
-
facebookAppId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
|
|
30
|
-
property: "fb:app_id",
|
|
31
|
-
content: facebookAppId
|
|
32
|
-
}),
|
|
33
|
-
gaId && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
34
|
-
async: true,
|
|
35
|
-
id: "gtag",
|
|
36
|
-
nonce,
|
|
37
|
-
src: gaSrc ?? `https://www.googletagmanager.com/gtag/js?id=${gaId}`
|
|
38
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
39
|
-
async: true,
|
|
40
|
-
nonce,
|
|
41
|
-
id: "gtag-init",
|
|
42
|
-
dangerouslySetInnerHTML: { __html: `
|
|
43
|
-
window.dataLayer = window.dataLayer || [];
|
|
44
|
-
function gtag(){dataLayer.push(arguments);}
|
|
45
|
-
gtag('js', new Date());
|
|
46
|
-
gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
|
|
47
|
-
` }
|
|
48
|
-
})] }),
|
|
49
|
-
metaPixelId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
50
|
-
async: true,
|
|
51
|
-
id: "meta-pixel",
|
|
52
|
-
nonce,
|
|
53
|
-
dangerouslySetInnerHTML: { __html: `
|
|
54
|
-
!(function (f, b, e, v, n, t, s) {
|
|
55
|
-
if (f.fbq) return;
|
|
56
|
-
n = f.fbq = function () {
|
|
57
|
-
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
58
|
-
};
|
|
59
|
-
if (!f._fbq) f._fbq = n;
|
|
60
|
-
n.push = n;
|
|
61
|
-
n.loaded = !0;
|
|
62
|
-
n.version = '2.0';
|
|
63
|
-
n.queue = [];
|
|
64
|
-
t = b.createElement(e);
|
|
65
|
-
t.async = !0;
|
|
66
|
-
t.src = v;
|
|
67
|
-
s = b.getElementsByTagName(e)[0];
|
|
68
|
-
s.parentNode.insertBefore(t, s);
|
|
69
|
-
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
70
|
-
fbq('init', '${metaPixelId}');
|
|
71
|
-
fbq('track', 'PageView');` }
|
|
72
|
-
}),
|
|
73
|
-
redditPixelId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
74
|
-
async: true,
|
|
75
|
-
id: "reddit-pixel",
|
|
76
|
-
nonce,
|
|
77
|
-
dangerouslySetInnerHTML: { __html: `
|
|
78
|
-
!function(w,d) {
|
|
79
|
-
if(!w.rdt) {
|
|
80
|
-
var p = w.rdt = function() {
|
|
81
|
-
p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)
|
|
82
|
-
};
|
|
83
|
-
p.callQueue = [];
|
|
84
|
-
var t = d.createElement("script");
|
|
85
|
-
t.src = "https://www.redditstatic.com/ads/pixel.js";
|
|
86
|
-
t.async = !0;
|
|
87
|
-
var s = d.getElementsByTagName("script")[0];
|
|
88
|
-
s.parentNode.insertBefore(t,s)
|
|
89
|
-
}
|
|
90
|
-
}(window, document);
|
|
91
|
-
rdt('init', '${redditPixelId}');
|
|
92
|
-
rdt('track', 'PageVisit');` }
|
|
93
|
-
}),
|
|
94
|
-
linkedInPartnerId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
95
|
-
async: true,
|
|
96
|
-
id: "linkedin-insight-tag",
|
|
97
|
-
nonce,
|
|
98
|
-
dangerouslySetInnerHTML: { __html: `
|
|
99
|
-
_linkedin_partner_id = "${linkedInPartnerId}";
|
|
100
|
-
window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
|
|
101
|
-
window._linkedin_data_partner_ids.push(_linkedin_partner_id);
|
|
102
|
-
|
|
103
|
-
(function(l) {
|
|
104
|
-
if (!l){
|
|
105
|
-
window.lintrk = function(a,b){
|
|
106
|
-
window.lintrk.q.push([a,b])
|
|
107
|
-
};
|
|
108
|
-
window.lintrk.q=[]
|
|
109
|
-
}
|
|
110
|
-
var s = document.getElementsByTagName("script")[0];
|
|
111
|
-
var b = document.createElement("script");
|
|
112
|
-
b.type = "text/javascript";b.async = true;
|
|
113
|
-
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
|
|
114
|
-
s.parentNode.insertBefore(b, s);
|
|
115
|
-
})(window.lintrk);
|
|
116
|
-
` }
|
|
117
|
-
}),
|
|
118
|
-
uetTagId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
119
|
-
async: true,
|
|
120
|
-
id: "uet-tag",
|
|
121
|
-
nonce,
|
|
122
|
-
dangerouslySetInnerHTML: { __html: `
|
|
123
|
-
(function (w, d, t, u, o) {
|
|
124
|
-
w[u] = w[u] || [], o.ts = (new Date).getTime();
|
|
125
|
-
var n = d.createElement(t);
|
|
126
|
-
n.src = "https://bat.bing.net/bat.js?ti=" + o.ti + ("uetq" != u ? "&q=" + u : ""),
|
|
127
|
-
n.async = 1, n.onload = n.onreadystatechange = function() {
|
|
128
|
-
var s = this.readyState;
|
|
129
|
-
s && "loaded" !== s && "complete" !== s ||
|
|
130
|
-
(o.q = w[u], w[u] = new UET(o), w[u].push("pageLoad"),
|
|
131
|
-
n.onload = n.onreadystatechange = null)
|
|
132
|
-
};
|
|
133
|
-
var i = d.getElementsByTagName(t)[0];
|
|
134
|
-
i.parentNode.insertBefore(n, i);
|
|
135
|
-
})(window, document, "script", "uetq", {
|
|
136
|
-
ti: "${uetTagId}",
|
|
137
|
-
enableAutoSpaTracking: true
|
|
138
|
-
});
|
|
139
|
-
` }
|
|
140
|
-
}),
|
|
141
|
-
hotjarId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
142
|
-
async: true,
|
|
143
|
-
id: "hotjar",
|
|
144
|
-
nonce,
|
|
145
|
-
dangerouslySetInnerHTML: { __html: `
|
|
146
|
-
(function(h,o,t,j,a,r){
|
|
147
|
-
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
148
|
-
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
149
|
-
a=o.getElementsByTagName('head')[0];
|
|
150
|
-
r=o.createElement('script');r.async=1;
|
|
151
|
-
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
152
|
-
a.appendChild(r);
|
|
153
|
-
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
154
|
-
` }
|
|
155
|
-
})
|
|
156
|
-
] });
|
|
157
|
-
}
|
|
158
|
-
exports.Analytics = Analytics;
|
|
159
|
-
|
|
160
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useLocation"],"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useLocation } from 'react-router';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useReportWebVitals } from '../hooks/use-report-web-vitals';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport type { PixelId as MetaPixelId } from '../track/fbq';\nimport type { GaId } from '../track/gtag';\nimport { track } from '../track/index';\nimport type { PixelId as RedditPixelId } from '../track/rdt';\n\ninterface Props {\n gaId?: GaId;\n gaSrc?: string;\n metaPixelId?: MetaPixelId;\n redditPixelId?: RedditPixelId;\n linkedInPartnerId?: `${number}`;\n /** Microsoft Advertising UET tag id. The tag reports page loads itself (`enableAutoSpaTracking`). */\n uetTagId?: `${number}`;\n /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the Conversions API's ID Sync pixel. */\n uetCustomerId?: `${number}`;\n hotjarId?: `${number}`;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function Analytics({\n gaId,\n gaSrc,\n nonce,\n debugMode,\n metaPixelId,\n redditPixelId,\n linkedInPartnerId,\n uetTagId,\n uetCustomerId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname, search } = useLocation();\n useWebAnalytics(pathname, search);\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerId);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {gaId && (\n <>\n <script\n async\n id=\"gtag\"\n nonce={nonce}\n src={gaSrc ?? `https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <script\n async\n nonce={nonce}\n id=\"gtag-init\"\n dangerouslySetInnerHTML={{\n __html: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${gaId}'${debugMode ? \" ,{ 'debug_mode': true }\" : ''});\n `,\n }}\n />\n </>\n )}\n {metaPixelId && (\n <script\n async\n id=\"meta-pixel\"\n nonce={nonce}\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${metaPixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {redditPixelId && (\n <script\n async\n id=\"reddit-pixel\"\n nonce={nonce}\n dangerouslySetInnerHTML={{\n __html: `\n !function(w,d) {\n if(!w.rdt) {\n var p = w.rdt = function() {\n p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)\n };\n p.callQueue = [];\n var t = d.createElement(\"script\");\n t.src = \"https://www.redditstatic.com/ads/pixel.js\";\n t.async = !0;\n var s = d.getElementsByTagName(\"script\")[0];\n s.parentNode.insertBefore(t,s)\n }\n }(window, document);\n rdt('init', '${redditPixelId}');\n rdt('track', 'PageVisit');`,\n }}\n />\n )}\n {linkedInPartnerId && (\n <script\n async\n id=\"linkedin-insight-tag\"\n nonce={nonce}\n dangerouslySetInnerHTML={{\n __html: `\n _linkedin_partner_id = \"${linkedInPartnerId}\";\n window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];\n window._linkedin_data_partner_ids.push(_linkedin_partner_id);\n\n (function(l) {\n if (!l){\n window.lintrk = function(a,b){\n window.lintrk.q.push([a,b])\n };\n window.lintrk.q=[]\n }\n var s = document.getElementsByTagName(\"script\")[0];\n var b = document.createElement(\"script\");\n b.type = \"text/javascript\";b.async = true;\n b.src = \"https://snap.licdn.com/li.lms-analytics/insight.min.js\";\n s.parentNode.insertBefore(b, s);\n })(window.lintrk);\n `,\n }}\n />\n )}\n {uetTagId && (\n <script\n async\n id=\"uet-tag\"\n nonce={nonce}\n dangerouslySetInnerHTML={{\n __html: `\n (function (w, d, t, u, o) {\n w[u] = w[u] || [], o.ts = (new Date).getTime();\n var n = d.createElement(t);\n n.src = \"https://bat.bing.net/bat.js?ti=\" + o.ti + (\"uetq\" != u ? \"&q=\" + u : \"\"),\n n.async = 1, n.onload = n.onreadystatechange = function() {\n var s = this.readyState;\n s && \"loaded\" !== s && \"complete\" !== s ||\n (o.q = w[u], w[u] = new UET(o), w[u].push(\"pageLoad\"),\n n.onload = n.onreadystatechange = null)\n };\n var i = d.getElementsByTagName(t)[0];\n i.parentNode.insertBefore(n, i);\n })(window, document, \"script\", \"uetq\", {\n ti: \"${uetTagId}\",\n enableAutoSpaTracking: true\n });\n `,\n }}\n />\n )}\n {hotjarId && (\n <script\n async\n id=\"hotjar\"\n nonce={nonce}\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,UAAU,EACxB,MACA,OACA,OACA,WACA,aACA,eACA,mBACA,UACA,eACA,UACA,eACA,kBAAkB,QACV;CACR,MAAM,EAAE,UAAU,YAAA,GAAWA,aAAAA,YAAAA,CAAY;CACzC,gCAAA,gBAAgB,UAAU,MAAM;CAChC,2CAAA,0BAA0B;CAC1B,8BAAA,aAAa,aAAa;CAE1B,oCAAA,oBAAoB,WAAW;EAC7B,IAAI,CAAC,iBAAiB;EACtB,MAAM,aAAa;GACjB,OAAO,OAAO;GACd,WAAW,OAAO;GAClB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;GACtB,wBAAwB,OAAO;GAC/B,iBAAiB;EACnB;EACA,oBAAA,MAAM,OAAO,MAAM,UAAU;CAC/B,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;EACG,iBAAiB,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrE,QACC,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA,CACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GACE,OAAA;GACA,IAAG;GACI;GACP,KAAK,SAAS,+CAA+C;EAC9D,CAAA,GACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GACE,OAAA;GACO;GACP,IAAG;GACH,yBAAyB,EACvB,QAAQ;;;;gCAIU,KAAK,GAAG,YAAY,6BAA6B,GAAG;cAExE;EACD,CAAA,CACD,EAAA,CAAA;EAEH,eACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GACE,OAAA;GACA,IAAG;GACI;GACP,yBAAyB,EACvB,QAAQ;;;;;;;;;;;;;;;;;2BAiBO,YAAY;uCAE7B;EACD,CAAA;EAEF,iBACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GACE,OAAA;GACA,IAAG;GACI;GACP,yBAAyB,EACvB,QAAQ;;;;;;;;;;;;;;2BAcO,cAAc;wCAE/B;EACD,CAAA;EAEF,qBACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GACE,OAAA;GACA,IAAG;GACI;GACP,yBAAyB,EACvB,QAAQ;sCACkB,kBAAkB;;;;;;;;;;;;;;;;;cAkB9C;EACD,CAAA;EAEF,YACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GACE,OAAA;GACA,IAAG;GACI;GACP,yBAAyB,EACvB,QAAQ;;;;;;;;;;;;;;uBAcG,SAAS;;;cAItB;EACD,CAAA;EAEF,YACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GACE,OAAA;GACA,IAAG;GACI;GACP,yBAAyB,EACvB,QAAQ;;;oCAGgB,SAAS;;;;;;cAOnC;EACD,CAAA;CAEH,EAAA,CAAA;AAEN"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { GaId } from "../track/gtag.cjs";
|
|
2
|
-
import { PixelId } from "../track/fbq.cjs";
|
|
3
|
-
import { PixelId as PixelId$1 } from "../track/rdt.cjs";
|
|
4
|
-
interface Props {
|
|
5
|
-
gaId?: GaId;
|
|
6
|
-
gaSrc?: string;
|
|
7
|
-
metaPixelId?: PixelId;
|
|
8
|
-
redditPixelId?: PixelId$1;
|
|
9
|
-
linkedInPartnerId?: `${number}`;
|
|
10
|
-
/** Microsoft Advertising UET tag id. The tag reports page loads itself (`enableAutoSpaTracking`). */
|
|
11
|
-
uetTagId?: `${number}`;
|
|
12
|
-
/** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the Conversions API's ID Sync pixel. */
|
|
13
|
-
uetCustomerId?: `${number}`;
|
|
14
|
-
hotjarId?: `${number}`;
|
|
15
|
-
facebookAppId?: string;
|
|
16
|
-
nonce?: string;
|
|
17
|
-
debugMode?: boolean;
|
|
18
|
-
reportWebVitals?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export declare function Analytics({ gaId, gaSrc, nonce, debugMode, metaPixelId, redditPixelId, linkedInPartnerId, uetTagId, uetCustomerId, hotjarId, facebookAppId, reportWebVitals }: Props): import("react").JSX.Element;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["MetaPixelId","RedditPixelId"],"sources":["../../src/react-router/index.tsx"],"mappings":";;;UAUU;EACR,OAAO;EACP;EACA,cAAcA;EACd,gBAAgBC;EAChB;;EAEA;;EAEA;EACA;EACA;EACA;EACA;EACA;;wBAGc,YACd,MACA,OACA,OACA,WACA,aACA,eACA,mBACA,UACA,eACA,UACA,eACA,mBACC,wBAAK,IAAA"}
|