@vercel/analytics 1.3.2 → 1.5.0-canary.1
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/dist/astro/component.ts +9 -0
- package/dist/astro/index.astro +40 -0
- package/dist/index.d.mts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +49 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -7
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.d.mts +4 -4
- package/dist/next/index.d.ts +4 -4
- package/dist/next/index.js +21 -20
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +21 -20
- package/dist/next/index.mjs.map +1 -1
- package/dist/nuxt/index.d.mts +33 -0
- package/dist/nuxt/index.d.ts +33 -0
- package/dist/nuxt/index.js +196 -0
- package/dist/nuxt/index.js.map +1 -0
- package/dist/nuxt/index.mjs +169 -0
- package/dist/nuxt/index.mjs.map +1 -0
- package/dist/react/index.d.mts +4 -3
- package/dist/react/index.d.ts +4 -3
- package/dist/react/index.js +17 -11
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +16 -10
- package/dist/react/index.mjs.map +1 -1
- package/dist/remix/index.d.mts +33 -0
- package/dist/remix/index.d.ts +33 -0
- package/dist/remix/index.js +209 -0
- package/dist/remix/index.js.map +1 -0
- package/dist/remix/index.mjs +174 -0
- package/dist/remix/index.mjs.map +1 -0
- package/dist/server/index.d.mts +12 -0
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/sveltekit/index.d.mts +46 -0
- package/dist/sveltekit/index.d.ts +46 -0
- package/dist/sveltekit/index.js +204 -0
- package/dist/sveltekit/index.js.map +1 -0
- package/dist/sveltekit/index.mjs +176 -0
- package/dist/sveltekit/index.mjs.map +1 -0
- package/dist/vue/index.d.mts +33 -0
- package/dist/vue/index.d.ts +33 -0
- package/dist/vue/index.js +196 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/index.mjs +169 -0
- package/dist/vue/index.mjs.map +1 -0
- package/jest.setup.ts +6 -3
- package/package.json +79 -26
- package/tsconfig.json +1 -1
- package/tsup.config.js +31 -5
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @ts-expect-error typescript doesn't handle ./index.astro properly, but it's needed to generate types
|
|
2
|
+
// eslint-disable-next-line import/no-default-export, no-useless-rename -- Exporting everything doesn't yield the desired outcome
|
|
3
|
+
export { default as default } from './index.astro';
|
|
4
|
+
export type {
|
|
5
|
+
AnalyticsProps,
|
|
6
|
+
BeforeSend,
|
|
7
|
+
BeforeSendEvent,
|
|
8
|
+
// @ts-expect-error this filed is copied to dist, so it's ok to reference the generated index.d.ts
|
|
9
|
+
} from '../index.d.ts';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Since this file will not be bundled by Tsup, it is referencing bundled files relative to dist/astro/
|
|
3
|
+
import type { AnalyticsProps } from '../index.d.ts';
|
|
4
|
+
type Props = Omit<AnalyticsProps, 'framework' | 'beforeSend'>;
|
|
5
|
+
|
|
6
|
+
const propsStr = JSON.stringify(Astro.props);
|
|
7
|
+
const paramsStr = JSON.stringify(Astro.params);
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<vercel-analytics
|
|
11
|
+
data-props={propsStr}
|
|
12
|
+
data-params={paramsStr}
|
|
13
|
+
data-pathname={Astro.url.pathname}></vercel-analytics>
|
|
14
|
+
|
|
15
|
+
<script>
|
|
16
|
+
import { inject, pageview, computeRoute } from '../index.mjs';
|
|
17
|
+
|
|
18
|
+
customElements.define(
|
|
19
|
+
'vercel-analytics',
|
|
20
|
+
class VercelAnalytics extends HTMLElement {
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
try {
|
|
24
|
+
const props = JSON.parse(this.dataset.props ?? '{}');
|
|
25
|
+
const params = JSON.parse(this.dataset.params ?? '{}');
|
|
26
|
+
inject({
|
|
27
|
+
...props,
|
|
28
|
+
disableAutoTrack: true,
|
|
29
|
+
framework: 'astro',
|
|
30
|
+
beforeSend: window.webAnalyticsBeforeSend,
|
|
31
|
+
});
|
|
32
|
+
const path = this.dataset.pathname;
|
|
33
|
+
pageview({ route: computeRoute(path ?? '', params), path });
|
|
34
|
+
} catch (err) {
|
|
35
|
+
throw new Error(`Failed to parse WebAnalytics properties: ${err}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
</script>
|
package/dist/index.d.mts
CHANGED
|
@@ -14,8 +14,6 @@ interface AnalyticsProps {
|
|
|
14
14
|
beforeSend?: BeforeSend;
|
|
15
15
|
debug?: boolean;
|
|
16
16
|
mode?: Mode;
|
|
17
|
-
route?: string | null;
|
|
18
|
-
disableAutoTrack?: boolean;
|
|
19
17
|
scriptSrc?: string;
|
|
20
18
|
endpoint?: string;
|
|
21
19
|
dsn?: string;
|
|
@@ -26,13 +24,18 @@ declare global {
|
|
|
26
24
|
vaq?: [string, unknown?][];
|
|
27
25
|
vai?: boolean;
|
|
28
26
|
vam?: Mode;
|
|
27
|
+
/** used by Astro component only */
|
|
28
|
+
webAnalyticsBeforeSend?: BeforeSend;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
type PlainFlags = Record<string, unknown>;
|
|
32
32
|
type FlagsDataInput = (string | PlainFlags)[] | PlainFlags;
|
|
33
33
|
|
|
34
|
+
declare function computeRoute(pathname: string | null, pathParams: Record<string, string | string[]> | null): string | null;
|
|
35
|
+
|
|
34
36
|
declare const DEV_SCRIPT_URL = "https://va.vercel-scripts.com/v1/script.debug.js";
|
|
35
37
|
declare const PROD_SCRIPT_URL = "/_vercel/insights/script.js";
|
|
38
|
+
declare const basepathVariableName = "NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH";
|
|
36
39
|
/**
|
|
37
40
|
* Injects the Vercel Web Analytics script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/concepts/analytics/package).
|
|
38
41
|
* @param [props] - Analytics options.
|
|
@@ -43,9 +46,11 @@ declare const PROD_SCRIPT_URL = "/_vercel/insights/script.js";
|
|
|
43
46
|
* @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.
|
|
44
47
|
* @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.
|
|
45
48
|
* @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.
|
|
49
|
+
* @param [props.disableAutoTrack] - Whether the injected script should track page views from pushState events. Disable if route is updated after pushState, a manually call page pageview().
|
|
46
50
|
*/
|
|
47
51
|
declare function inject(props?: AnalyticsProps & {
|
|
48
52
|
framework?: string;
|
|
53
|
+
disableAutoTrack?: boolean;
|
|
49
54
|
}): void;
|
|
50
55
|
/**
|
|
51
56
|
* Tracks a custom event. Please refer to the [documentation](https://vercel.com/docs/concepts/analytics/custom-events) for more information on custom events.
|
|
@@ -56,14 +61,15 @@ declare function inject(props?: AnalyticsProps & {
|
|
|
56
61
|
declare function track(name: string, properties?: Record<string, AllowedPropertyValues>, options?: {
|
|
57
62
|
flags?: FlagsDataInput;
|
|
58
63
|
}): void;
|
|
59
|
-
declare function pageview({ route, path }: {
|
|
60
|
-
route?: string;
|
|
64
|
+
declare function pageview({ route, path, }: {
|
|
65
|
+
route?: string | null;
|
|
61
66
|
path?: string;
|
|
62
67
|
}): void;
|
|
63
68
|
|
|
64
69
|
declare const _default: {
|
|
65
70
|
inject: typeof inject;
|
|
66
71
|
track: typeof track;
|
|
72
|
+
computeRoute: typeof computeRoute;
|
|
67
73
|
};
|
|
68
74
|
|
|
69
|
-
export { AnalyticsProps, DEV_SCRIPT_URL, PROD_SCRIPT_URL, _default as default, inject, pageview, track };
|
|
75
|
+
export { AnalyticsProps, BeforeSend, BeforeSendEvent, DEV_SCRIPT_URL, PROD_SCRIPT_URL, basepathVariableName, computeRoute, _default as default, inject, pageview, track };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,8 +14,6 @@ interface AnalyticsProps {
|
|
|
14
14
|
beforeSend?: BeforeSend;
|
|
15
15
|
debug?: boolean;
|
|
16
16
|
mode?: Mode;
|
|
17
|
-
route?: string | null;
|
|
18
|
-
disableAutoTrack?: boolean;
|
|
19
17
|
scriptSrc?: string;
|
|
20
18
|
endpoint?: string;
|
|
21
19
|
dsn?: string;
|
|
@@ -26,13 +24,18 @@ declare global {
|
|
|
26
24
|
vaq?: [string, unknown?][];
|
|
27
25
|
vai?: boolean;
|
|
28
26
|
vam?: Mode;
|
|
27
|
+
/** used by Astro component only */
|
|
28
|
+
webAnalyticsBeforeSend?: BeforeSend;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
type PlainFlags = Record<string, unknown>;
|
|
32
32
|
type FlagsDataInput = (string | PlainFlags)[] | PlainFlags;
|
|
33
33
|
|
|
34
|
+
declare function computeRoute(pathname: string | null, pathParams: Record<string, string | string[]> | null): string | null;
|
|
35
|
+
|
|
34
36
|
declare const DEV_SCRIPT_URL = "https://va.vercel-scripts.com/v1/script.debug.js";
|
|
35
37
|
declare const PROD_SCRIPT_URL = "/_vercel/insights/script.js";
|
|
38
|
+
declare const basepathVariableName = "NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH";
|
|
36
39
|
/**
|
|
37
40
|
* Injects the Vercel Web Analytics script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/concepts/analytics/package).
|
|
38
41
|
* @param [props] - Analytics options.
|
|
@@ -43,9 +46,11 @@ declare const PROD_SCRIPT_URL = "/_vercel/insights/script.js";
|
|
|
43
46
|
* @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.
|
|
44
47
|
* @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.
|
|
45
48
|
* @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.
|
|
49
|
+
* @param [props.disableAutoTrack] - Whether the injected script should track page views from pushState events. Disable if route is updated after pushState, a manually call page pageview().
|
|
46
50
|
*/
|
|
47
51
|
declare function inject(props?: AnalyticsProps & {
|
|
48
52
|
framework?: string;
|
|
53
|
+
disableAutoTrack?: boolean;
|
|
49
54
|
}): void;
|
|
50
55
|
/**
|
|
51
56
|
* Tracks a custom event. Please refer to the [documentation](https://vercel.com/docs/concepts/analytics/custom-events) for more information on custom events.
|
|
@@ -56,14 +61,15 @@ declare function inject(props?: AnalyticsProps & {
|
|
|
56
61
|
declare function track(name: string, properties?: Record<string, AllowedPropertyValues>, options?: {
|
|
57
62
|
flags?: FlagsDataInput;
|
|
58
63
|
}): void;
|
|
59
|
-
declare function pageview({ route, path }: {
|
|
60
|
-
route?: string;
|
|
64
|
+
declare function pageview({ route, path, }: {
|
|
65
|
+
route?: string | null;
|
|
61
66
|
path?: string;
|
|
62
67
|
}): void;
|
|
63
68
|
|
|
64
69
|
declare const _default: {
|
|
65
70
|
inject: typeof inject;
|
|
66
71
|
track: typeof track;
|
|
72
|
+
computeRoute: typeof computeRoute;
|
|
67
73
|
};
|
|
68
74
|
|
|
69
|
-
export { AnalyticsProps, DEV_SCRIPT_URL, PROD_SCRIPT_URL, _default as default, inject, pageview, track };
|
|
75
|
+
export { AnalyticsProps, BeforeSend, BeforeSendEvent, DEV_SCRIPT_URL, PROD_SCRIPT_URL, basepathVariableName, computeRoute, _default as default, inject, pageview, track };
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ var generic_exports = {};
|
|
|
22
22
|
__export(generic_exports, {
|
|
23
23
|
DEV_SCRIPT_URL: () => DEV_SCRIPT_URL,
|
|
24
24
|
PROD_SCRIPT_URL: () => PROD_SCRIPT_URL,
|
|
25
|
+
basepathVariableName: () => basepathVariableName,
|
|
26
|
+
computeRoute: () => computeRoute,
|
|
25
27
|
default: () => generic_default,
|
|
26
28
|
inject: () => inject,
|
|
27
29
|
pageview: () => pageview,
|
|
@@ -31,7 +33,7 @@ module.exports = __toCommonJS(generic_exports);
|
|
|
31
33
|
|
|
32
34
|
// package.json
|
|
33
35
|
var name = "@vercel/analytics";
|
|
34
|
-
var version = "1.
|
|
36
|
+
var version = "1.5.0-canary.1";
|
|
35
37
|
|
|
36
38
|
// src/queue.ts
|
|
37
39
|
var initQueue = () => {
|
|
@@ -99,10 +101,45 @@ function parseProperties(properties, options) {
|
|
|
99
101
|
}
|
|
100
102
|
return props;
|
|
101
103
|
}
|
|
104
|
+
function computeRoute(pathname, pathParams) {
|
|
105
|
+
if (!pathname || !pathParams) {
|
|
106
|
+
return pathname;
|
|
107
|
+
}
|
|
108
|
+
let result = pathname;
|
|
109
|
+
try {
|
|
110
|
+
const entries = Object.entries(pathParams);
|
|
111
|
+
for (const [key, value] of entries) {
|
|
112
|
+
if (!Array.isArray(value)) {
|
|
113
|
+
const matcher = turnValueToRegExp(value);
|
|
114
|
+
if (matcher.test(result)) {
|
|
115
|
+
result = result.replace(matcher, `/[${key}]`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const [key, value] of entries) {
|
|
120
|
+
if (Array.isArray(value)) {
|
|
121
|
+
const matcher = turnValueToRegExp(value.join("/"));
|
|
122
|
+
if (matcher.test(result)) {
|
|
123
|
+
result = result.replace(matcher, `/[...${key}]`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
} catch (e) {
|
|
129
|
+
return pathname;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function turnValueToRegExp(value) {
|
|
133
|
+
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
|
134
|
+
}
|
|
135
|
+
function escapeRegExp(string) {
|
|
136
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
137
|
+
}
|
|
102
138
|
|
|
103
139
|
// src/generic.ts
|
|
104
140
|
var DEV_SCRIPT_URL = "https://va.vercel-scripts.com/v1/script.debug.js";
|
|
105
141
|
var PROD_SCRIPT_URL = "/_vercel/insights/script.js";
|
|
142
|
+
var basepathVariableName = "NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH";
|
|
106
143
|
function inject(props = {
|
|
107
144
|
debug: true
|
|
108
145
|
}) {
|
|
@@ -127,6 +164,8 @@ function inject(props = {
|
|
|
127
164
|
}
|
|
128
165
|
if (props.endpoint) {
|
|
129
166
|
script.dataset.endpoint = props.endpoint;
|
|
167
|
+
} else if (process.env[basepathVariableName]) {
|
|
168
|
+
script.dataset.endpoint = `/${process.env[basepathVariableName]}/_vercel/insights`;
|
|
130
169
|
}
|
|
131
170
|
if (props.dsn) {
|
|
132
171
|
script.dataset.dsn = props.dsn;
|
|
@@ -172,21 +211,24 @@ function track(name2, properties, options) {
|
|
|
172
211
|
}
|
|
173
212
|
}
|
|
174
213
|
}
|
|
175
|
-
function pageview({
|
|
214
|
+
function pageview({
|
|
215
|
+
route,
|
|
216
|
+
path
|
|
217
|
+
}) {
|
|
176
218
|
var _a;
|
|
177
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
178
|
-
route,
|
|
179
|
-
path
|
|
180
|
-
});
|
|
219
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", { route, path });
|
|
181
220
|
}
|
|
182
221
|
var generic_default = {
|
|
183
222
|
inject,
|
|
184
|
-
track
|
|
223
|
+
track,
|
|
224
|
+
computeRoute
|
|
185
225
|
};
|
|
186
226
|
// Annotate the CommonJS export names for ESM import in node:
|
|
187
227
|
0 && (module.exports = {
|
|
188
228
|
DEV_SCRIPT_URL,
|
|
189
229
|
PROD_SCRIPT_URL,
|
|
230
|
+
basepathVariableName,
|
|
231
|
+
computeRoute,
|
|
190
232
|
inject,
|
|
191
233
|
pageview,
|
|
192
234
|
track
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generic.ts","../package.json","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\n\n/**\n * Injects the Vercel Web Analytics script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/concepts/analytics/package).\n * @param [props] - Analytics options.\n * @param [props.mode] - The mode to use for the analytics script. Defaults to `auto`.\n * - `auto` - Automatically detect the environment. Uses `production` if the environment cannot be determined.\n * - `production` - Always use the production script. (Sends events to the server)\n * - `development` - Always use the development script. (Logs events to the console)\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n } = {\n debug: true,\n }\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.';\n\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n document.head.appendChild(script);\n}\n\n/**\n * Tracks a custom event. Please refer to the [documentation](https://vercel.com/docs/concepts/analytics/custom-events) for more information on custom events.\n * @param name - The name of the event.\n * * Examples: `Purchase`, `Click Button`, or `Play Video`.\n * @param [properties] - Additional properties of the event. Nested objects are not supported. Allowed values are `string`, `number`, `boolean`, and `null`.\n */\nfunction track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n options?: {\n flags?: FlagsDataInput;\n }\n): void {\n if (!isBrowser()) {\n const msg =\n '[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment';\n\n if (isProduction()) {\n // eslint-disable-next-line no-console -- Show warning in production\n console.warn(msg);\n } else {\n throw new Error(msg);\n }\n\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name, options });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n options,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.3.2\",\n \"description\": \"Gain real-time traffic insights with Vercel Web Analytics\",\n \"keywords\": [\n \"analytics\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/analytics\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.mjs\",\n \"import\": \"./dist/server/index.mjs\",\n \"require\": \"./dist/server/index.js\",\n \"default\": \"./dist/server/index.js\"\n }\n },\n \"main\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\n },\n \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18.0 || ^19.0 || ^19.0.0-rc\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n }\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n const mode = isBrowser() ? window.vam : detectEnvironment();\n return mode || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest }\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown> | undefined,\n options: {\n strip?: boolean;\n }\n): Error | Record<string, AllowedPropertyValues> | undefined {\n if (!properties) return undefined;\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', '\n )}. Only strings, numbers, booleans, and null are allowed.`\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,Q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
|
1
|
+
{"version":3,"sources":["../src/generic.ts","../package.json","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n BeforeSend,\n BeforeSendEvent,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n computeRoute,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\n\nexport const basepathVariableName = 'NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH';\n\n/**\n * Injects the Vercel Web Analytics script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/concepts/analytics/package).\n * @param [props] - Analytics options.\n * @param [props.mode] - The mode to use for the analytics script. Defaults to `auto`.\n * - `auto` - Automatically detect the environment. Uses `production` if the environment cannot be determined.\n * - `production` - Always use the production script. (Sends events to the server)\n * - `development` - Always use the development script. (Logs events to the console)\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [props.disableAutoTrack] - Whether the injected script should track page views from pushState events. Disable if route is updated after pushState, a manually call page pageview().\n */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n disableAutoTrack?: boolean;\n } = {\n debug: true,\n }\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n } else if (process.env[basepathVariableName]) {\n script.dataset.endpoint = `/${process.env[basepathVariableName]}/_vercel/insights`;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.';\n\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n document.head.appendChild(script);\n}\n\n/**\n * Tracks a custom event. Please refer to the [documentation](https://vercel.com/docs/concepts/analytics/custom-events) for more information on custom events.\n * @param name - The name of the event.\n * * Examples: `Purchase`, `Click Button`, or `Play Video`.\n * @param [properties] - Additional properties of the event. Nested objects are not supported. Allowed values are `string`, `number`, `boolean`, and `null`.\n */\nfunction track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n options?: {\n flags?: FlagsDataInput;\n }\n): void {\n if (!isBrowser()) {\n const msg =\n '[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment';\n\n if (isProduction()) {\n // eslint-disable-next-line no-console -- Show warning in production\n console.warn(msg);\n } else {\n throw new Error(msg);\n }\n\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name, options });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n options,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({\n route,\n path,\n}: {\n route?: string | null;\n path?: string;\n}): void {\n window.va?.('pageview', { route, path });\n}\n\nexport { inject, track, pageview, computeRoute };\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n computeRoute,\n};\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.5.0-canary.1\",\n \"description\": \"Gain real-time traffic insights with Vercel Web Analytics\",\n \"keywords\": [\n \"analytics\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/analytics\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"browser\": \"./dist/nuxt/index.mjs\",\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.mjs\",\n \"import\": \"./dist/server/index.mjs\",\n \"require\": \"./dist/server/index.js\",\n \"default\": \"./dist/server/index.js\"\n },\n \"./sveltekit\": {\n \"svelte\": \"./dist/sveltekit/index.mjs\",\n \"types\": \"./dist/sveltekit/index.d.ts\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\n },\n \"devDependencies\": {\n \"@jest/globals\": \"^29.7.0\",\n \"@swc/core\": \"^1.8.0\",\n \"@swc/jest\": \"^0.2.37\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^20.17.6\",\n \"@types/react\": \"^18.3.12\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.7.0\",\n \"jest-environment-jsdom\": \"^29.7.0\",\n \"server-only\": \"^0.0.1\",\n \"svelte\": \"^5.1.10\",\n \"tsup\": \"7.1.0\",\n \"vue\": \"^3.5.12\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@remix-run/react\": \"^2\",\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@remix-run/react\": {\n \"optional\": true\n },\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n const mode = isBrowser() ? window.vam : detectEnvironment();\n return mode || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest }\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown> | undefined,\n options: {\n strip?: boolean;\n }\n): Error | Record<string, AllowedPropertyValues> | undefined {\n if (!properties) return undefined;\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', '\n )}. Only strings, numbers, booleans, and null are allowed.`\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AA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.
|
|
3
|
+
var version = "1.5.0-canary.1";
|
|
4
4
|
|
|
5
5
|
// src/queue.ts
|
|
6
6
|
var initQueue = () => {
|
|
@@ -68,10 +68,45 @@ function parseProperties(properties, options) {
|
|
|
68
68
|
}
|
|
69
69
|
return props;
|
|
70
70
|
}
|
|
71
|
+
function computeRoute(pathname, pathParams) {
|
|
72
|
+
if (!pathname || !pathParams) {
|
|
73
|
+
return pathname;
|
|
74
|
+
}
|
|
75
|
+
let result = pathname;
|
|
76
|
+
try {
|
|
77
|
+
const entries = Object.entries(pathParams);
|
|
78
|
+
for (const [key, value] of entries) {
|
|
79
|
+
if (!Array.isArray(value)) {
|
|
80
|
+
const matcher = turnValueToRegExp(value);
|
|
81
|
+
if (matcher.test(result)) {
|
|
82
|
+
result = result.replace(matcher, `/[${key}]`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const [key, value] of entries) {
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
const matcher = turnValueToRegExp(value.join("/"));
|
|
89
|
+
if (matcher.test(result)) {
|
|
90
|
+
result = result.replace(matcher, `/[...${key}]`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return pathname;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function turnValueToRegExp(value) {
|
|
100
|
+
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
|
101
|
+
}
|
|
102
|
+
function escapeRegExp(string) {
|
|
103
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
104
|
+
}
|
|
71
105
|
|
|
72
106
|
// src/generic.ts
|
|
73
107
|
var DEV_SCRIPT_URL = "https://va.vercel-scripts.com/v1/script.debug.js";
|
|
74
108
|
var PROD_SCRIPT_URL = "/_vercel/insights/script.js";
|
|
109
|
+
var basepathVariableName = "NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH";
|
|
75
110
|
function inject(props = {
|
|
76
111
|
debug: true
|
|
77
112
|
}) {
|
|
@@ -96,6 +131,8 @@ function inject(props = {
|
|
|
96
131
|
}
|
|
97
132
|
if (props.endpoint) {
|
|
98
133
|
script.dataset.endpoint = props.endpoint;
|
|
134
|
+
} else if (process.env[basepathVariableName]) {
|
|
135
|
+
script.dataset.endpoint = `/${process.env[basepathVariableName]}/_vercel/insights`;
|
|
99
136
|
}
|
|
100
137
|
if (props.dsn) {
|
|
101
138
|
script.dataset.dsn = props.dsn;
|
|
@@ -141,20 +178,23 @@ function track(name2, properties, options) {
|
|
|
141
178
|
}
|
|
142
179
|
}
|
|
143
180
|
}
|
|
144
|
-
function pageview({
|
|
181
|
+
function pageview({
|
|
182
|
+
route,
|
|
183
|
+
path
|
|
184
|
+
}) {
|
|
145
185
|
var _a;
|
|
146
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
147
|
-
route,
|
|
148
|
-
path
|
|
149
|
-
});
|
|
186
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", { route, path });
|
|
150
187
|
}
|
|
151
188
|
var generic_default = {
|
|
152
189
|
inject,
|
|
153
|
-
track
|
|
190
|
+
track,
|
|
191
|
+
computeRoute
|
|
154
192
|
};
|
|
155
193
|
export {
|
|
156
194
|
DEV_SCRIPT_URL,
|
|
157
195
|
PROD_SCRIPT_URL,
|
|
196
|
+
basepathVariableName,
|
|
197
|
+
computeRoute,
|
|
158
198
|
generic_default as default,
|
|
159
199
|
inject,
|
|
160
200
|
pageview,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/queue.ts","../src/utils.ts","../src/generic.ts"],"sourcesContent":["{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.3.2\",\n \"description\": \"Gain real-time traffic insights with Vercel Web Analytics\",\n \"keywords\": [\n \"analytics\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/analytics\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.mjs\",\n \"import\": \"./dist/server/index.mjs\",\n \"require\": \"./dist/server/index.js\",\n \"default\": \"./dist/server/index.js\"\n }\n },\n \"main\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\n },\n \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18.0 || ^19.0 || ^19.0.0-rc\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n }\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n const mode = isBrowser() ? window.vam : detectEnvironment();\n return mode || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest }\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown> | undefined,\n options: {\n strip?: boolean;\n }\n): Error | Record<string, AllowedPropertyValues> | undefined {\n if (!properties) return undefined;\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', '\n )}. Only strings, numbers, booleans, and null are allowed.`\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\n\n/**\n * Injects the Vercel Web Analytics script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/concepts/analytics/package).\n * @param [props] - Analytics options.\n * @param [props.mode] - The mode to use for the analytics script. Defaults to `auto`.\n * - `auto` - Automatically detect the environment. Uses `production` if the environment cannot be determined.\n * - `production` - Always use the production script. (Sends events to the server)\n * - `development` - Always use the development script. (Logs events to the console)\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n } = {\n debug: true,\n }\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.';\n\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n document.head.appendChild(script);\n}\n\n/**\n * Tracks a custom event. Please refer to the [documentation](https://vercel.com/docs/concepts/analytics/custom-events) for more information on custom events.\n * @param name - The name of the event.\n * * Examples: `Purchase`, `Click Button`, or `Play Video`.\n * @param [properties] - Additional properties of the event. Nested objects are not supported. Allowed values are `string`, `number`, `boolean`, and `null`.\n */\nfunction track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n options?: {\n flags?: FlagsDataInput;\n }\n): void {\n if (!isBrowser()) {\n const msg =\n '[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment';\n\n if (isProduction()) {\n // eslint-disable-next-line no-console -- Show warning in production\n console.warn(msg);\n } else {\n throw new Error(msg);\n }\n\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name, options });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n options,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n"],"mappings":";AACE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AACvB;AAEA,SAAS,UACP,KAC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AI,MAAM,KAAK;AACb,WAAO,QAAQ,MAAM,MAAM;AAAA,EAC7B;AAEA,SAAO,UAAU,MAAY;AAC3B,UAAM,eAAe,cAAc,IAC/B,+DACA;AAGJ,YAAQ;AAAA,MACN,qDAAqD,GAAG,KAAK,YAAY;AAAA,IAC3E;AAAA,EACF;AAEA,MAAI,cAAc,KAAK,MAAM,UAAU,OAAO;AAC5C,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;AAQA,SAAS,MACPA,OACA,YACA,SAGM;AAnGR;AAoGE,MAAI,CAAC,UAAU,GAAG;AAChB,UAAM,MACJ;AAEF,QAAI,aAAa,GAAG;AAElB,cAAQ,KAAK,GAAG;AAAA,IAClB,OAAO;AACL,YAAM,IAAI,MAAM,GAAG;AAAA,IACrB;AAEA;AAAA,EACF;AAEA,MAAI,CAAC,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,OAAM,QAAQ;AACrC;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,MACN;AAAA,IACF;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS,EAAE,OAAO,KAAK,GAA4C;AAzI5E;AA0IE,eAAO,OAAP,gCAAY,YAAY;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AACF;AAMA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/queue.ts","../src/utils.ts","../src/generic.ts"],"sourcesContent":["{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.5.0-canary.1\",\n \"description\": \"Gain real-time traffic insights with Vercel Web Analytics\",\n \"keywords\": [\n \"analytics\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/analytics\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"browser\": \"./dist/nuxt/index.mjs\",\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.mjs\",\n \"import\": \"./dist/server/index.mjs\",\n \"require\": \"./dist/server/index.js\",\n \"default\": \"./dist/server/index.js\"\n },\n \"./sveltekit\": {\n \"svelte\": \"./dist/sveltekit/index.mjs\",\n \"types\": \"./dist/sveltekit/index.d.ts\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\n },\n \"devDependencies\": {\n \"@jest/globals\": \"^29.7.0\",\n \"@swc/core\": \"^1.8.0\",\n \"@swc/jest\": \"^0.2.37\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^20.17.6\",\n \"@types/react\": \"^18.3.12\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.7.0\",\n \"jest-environment-jsdom\": \"^29.7.0\",\n \"server-only\": \"^0.0.1\",\n \"svelte\": \"^5.1.10\",\n \"tsup\": \"7.1.0\",\n \"vue\": \"^3.5.12\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@remix-run/react\": \"^2\",\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@remix-run/react\": {\n \"optional\": true\n },\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n const mode = isBrowser() ? window.vam : detectEnvironment();\n return mode || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest }\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown> | undefined,\n options: {\n strip?: boolean;\n }\n): Error | Record<string, AllowedPropertyValues> | undefined {\n if (!properties) return undefined;\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', '\n )}. Only strings, numbers, booleans, and null are allowed.`\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n BeforeSend,\n BeforeSendEvent,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n computeRoute,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\n\nexport const basepathVariableName = 'NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH';\n\n/**\n * Injects the Vercel Web Analytics script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/concepts/analytics/package).\n * @param [props] - Analytics options.\n * @param [props.mode] - The mode to use for the analytics script. Defaults to `auto`.\n * - `auto` - Automatically detect the environment. Uses `production` if the environment cannot be determined.\n * - `production` - Always use the production script. (Sends events to the server)\n * - `development` - Always use the development script. (Logs events to the console)\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [props.disableAutoTrack] - Whether the injected script should track page views from pushState events. Disable if route is updated after pushState, a manually call page pageview().\n */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n disableAutoTrack?: boolean;\n } = {\n debug: true,\n }\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n } else if (process.env[basepathVariableName]) {\n script.dataset.endpoint = `/${process.env[basepathVariableName]}/_vercel/insights`;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.';\n\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n document.head.appendChild(script);\n}\n\n/**\n * Tracks a custom event. Please refer to the [documentation](https://vercel.com/docs/concepts/analytics/custom-events) for more information on custom events.\n * @param name - The name of the event.\n * * Examples: `Purchase`, `Click Button`, or `Play Video`.\n * @param [properties] - Additional properties of the event. Nested objects are not supported. Allowed values are `string`, `number`, `boolean`, and `null`.\n */\nfunction track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n options?: {\n flags?: FlagsDataInput;\n }\n): void {\n if (!isBrowser()) {\n const msg =\n '[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment';\n\n if (isProduction()) {\n // eslint-disable-next-line no-console -- Show warning in production\n console.warn(msg);\n } else {\n throw new Error(msg);\n }\n\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name, options });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n options,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({\n route,\n path,\n}: {\n route?: string | null;\n path?: string;\n}): void {\n window.va?.('pageview', { route, path });\n}\n\nexport { inject, track, pageview, computeRoute };\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n computeRoute,\n};\n"],"mappings":";AACE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;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,KAAK,MAAM,UAAU,OAAO;AAC5C,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;AAQA,SAAS,MACPA,OACA,YACA,SAGM;AA5GR;AA6GE,MAAI,CAAC,UAAU,GAAG;AAChB,UAAM,MACJ;AAEF,QAAI,aAAa,GAAG;AAElB,cAAQ,KAAK,GAAG;AAAA,IAClB,OAAO;AACL,YAAM,IAAI,MAAM,GAAG;AAAA,IACrB;AAEA;AAAA,EACF;AAEA,MAAI,CAAC,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,OAAM,QAAQ;AACrC;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,MACN;AAAA,IACF;AAAA,EACF,SAAS,KAAK;AACZ,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS;AAAA,EAChB;AAAA,EACA;AACF,GAGS;AAxJT;AAyJE,eAAO,OAAP,gCAAY,YAAY,EAAE,OAAO,KAAK;AACxC;AAMA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AACF;","names":["name"]}
|
package/dist/next/index.d.mts
CHANGED
|
@@ -13,8 +13,6 @@ interface AnalyticsProps {
|
|
|
13
13
|
beforeSend?: BeforeSend;
|
|
14
14
|
debug?: boolean;
|
|
15
15
|
mode?: Mode;
|
|
16
|
-
route?: string | null;
|
|
17
|
-
disableAutoTrack?: boolean;
|
|
18
16
|
scriptSrc?: string;
|
|
19
17
|
endpoint?: string;
|
|
20
18
|
dsn?: string;
|
|
@@ -25,10 +23,12 @@ declare global {
|
|
|
25
23
|
vaq?: [string, unknown?][];
|
|
26
24
|
vai?: boolean;
|
|
27
25
|
vam?: Mode;
|
|
26
|
+
/** used by Astro component only */
|
|
27
|
+
webAnalyticsBeforeSend?: BeforeSend;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
type Props = Omit<AnalyticsProps, 'route'>;
|
|
31
|
+
type Props = Omit<AnalyticsProps, 'route' | 'disableAutoTrack'>;
|
|
32
32
|
declare function Analytics(props: Props): null;
|
|
33
33
|
|
|
34
|
-
export { Analytics, AnalyticsProps };
|
|
34
|
+
export { Analytics, AnalyticsProps, BeforeSend, BeforeSendEvent };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -13,8 +13,6 @@ interface AnalyticsProps {
|
|
|
13
13
|
beforeSend?: BeforeSend;
|
|
14
14
|
debug?: boolean;
|
|
15
15
|
mode?: Mode;
|
|
16
|
-
route?: string | null;
|
|
17
|
-
disableAutoTrack?: boolean;
|
|
18
16
|
scriptSrc?: string;
|
|
19
17
|
endpoint?: string;
|
|
20
18
|
dsn?: string;
|
|
@@ -25,10 +23,12 @@ declare global {
|
|
|
25
23
|
vaq?: [string, unknown?][];
|
|
26
24
|
vai?: boolean;
|
|
27
25
|
vam?: Mode;
|
|
26
|
+
/** used by Astro component only */
|
|
27
|
+
webAnalyticsBeforeSend?: BeforeSend;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
type Props = Omit<AnalyticsProps, 'route'>;
|
|
31
|
+
type Props = Omit<AnalyticsProps, 'route' | 'disableAutoTrack'>;
|
|
32
32
|
declare function Analytics(props: Props): null;
|
|
33
33
|
|
|
34
|
-
export { Analytics, AnalyticsProps };
|
|
34
|
+
export { Analytics, AnalyticsProps, BeforeSend, BeforeSendEvent };
|