vercel analytics script on both pages; disable project SSO protection (was 404-ing visitors)
This commit is contained in:
1 parent
cc6a660729
commit
632d053de9
68 files changed
+5662
No files matched your search
+36
@@ -0,0 +1,36 @@
|
||||
interface PageViewEvent {
|
||||
type: 'pageview';
|
||||
url: string;
|
||||
}
|
||||
interface CustomEvent {
|
||||
type: 'event';
|
||||
url: string;
|
||||
}
|
||||
type BeforeSendEvent = PageViewEvent | CustomEvent;
|
||||
type Mode = 'auto' | 'development' | 'production';
|
||||
type BeforeSend = (event: BeforeSendEvent) => BeforeSendEvent | null;
|
||||
interface AnalyticsProps {
|
||||
beforeSend?: BeforeSend;
|
||||
debug?: boolean;
|
||||
mode?: Mode;
|
||||
scriptSrc?: string;
|
||||
dsn?: string;
|
||||
eventEndpoint?: string;
|
||||
viewEndpoint?: string;
|
||||
sessionEndpoint?: string;
|
||||
endpoint?: string;
|
||||
}
|
||||
declare global {
|
||||
interface Window {
|
||||
va?: (event: 'beforeSend' | 'event' | 'pageview', properties?: unknown) => void;
|
||||
vaq?: [string, unknown?][];
|
||||
vai?: boolean;
|
||||
vam?: Mode;
|
||||
/** used by Astro component only */
|
||||
webAnalyticsBeforeSend?: BeforeSend;
|
||||
}
|
||||
}
|
||||
|
||||
declare const Analytics: any;
|
||||
|
||||
export { Analytics, type AnalyticsProps, type BeforeSend, type BeforeSendEvent };
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
interface PageViewEvent {
|
||||
type: 'pageview';
|
||||
url: string;
|
||||
}
|
||||
interface CustomEvent {
|
||||
type: 'event';
|
||||
url: string;
|
||||
}
|
||||
type BeforeSendEvent = PageViewEvent | CustomEvent;
|
||||
type Mode = 'auto' | 'development' | 'production';
|
||||
type BeforeSend = (event: BeforeSendEvent) => BeforeSendEvent | null;
|
||||
interface AnalyticsProps {
|
||||
beforeSend?: BeforeSend;
|
||||
debug?: boolean;
|
||||
mode?: Mode;
|
||||
scriptSrc?: string;
|
||||
dsn?: string;
|
||||
eventEndpoint?: string;
|
||||
viewEndpoint?: string;
|
||||
sessionEndpoint?: string;
|
||||
endpoint?: string;
|
||||
}
|
||||
declare global {
|
||||
interface Window {
|
||||
va?: (event: 'beforeSend' | 'event' | 'pageview', properties?: unknown) => void;
|
||||
vaq?: [string, unknown?][];
|
||||
vai?: boolean;
|
||||
vam?: Mode;
|
||||
/** used by Astro component only */
|
||||
webAnalyticsBeforeSend?: BeforeSend;
|
||||
}
|
||||
}
|
||||
|
||||
declare const Analytics: any;
|
||||
|
||||
export { Analytics, type AnalyticsProps, type BeforeSend, type BeforeSendEvent };
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name2 in all)
|
||||
__defProp(target, name2, { get: all[name2], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/vue/index.ts
|
||||
var vue_exports = {};
|
||||
__export(vue_exports, {
|
||||
Analytics: () => Analytics
|
||||
});
|
||||
module.exports = __toCommonJS(vue_exports);
|
||||
|
||||
// src/vue/create-component.ts
|
||||
var import_vue = require("vue");
|
||||
var import_vue_router = require("vue-router");
|
||||
|
||||
// src/queue.ts
|
||||
var initQueue = () => {
|
||||
if (window.va) return;
|
||||
window.va = function a(...params) {
|
||||
if (!window.vaq) window.vaq = [];
|
||||
window.vaq.push(params);
|
||||
};
|
||||
};
|
||||
|
||||
// package.json
|
||||
var name = "@vercel/analytics";
|
||||
var version = "2.0.1";
|
||||
|
||||
// src/utils.ts
|
||||
function isBrowser() {
|
||||
return typeof window !== "undefined";
|
||||
}
|
||||
function detectEnvironment() {
|
||||
try {
|
||||
const env = process.env.NODE_ENV;
|
||||
if (env === "development" || env === "test") {
|
||||
return "development";
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return "production";
|
||||
}
|
||||
function setMode(mode = "auto") {
|
||||
if (mode === "auto") {
|
||||
window.vam = detectEnvironment();
|
||||
return;
|
||||
}
|
||||
window.vam = mode;
|
||||
}
|
||||
function getMode() {
|
||||
const mode = isBrowser() ? window.vam : detectEnvironment();
|
||||
return mode || "production";
|
||||
}
|
||||
function isDevelopment() {
|
||||
return getMode() === "development";
|
||||
}
|
||||
function computeRoute(pathname, pathParams) {
|
||||
if (!pathname || !pathParams) {
|
||||
return pathname;
|
||||
}
|
||||
let result = pathname;
|
||||
try {
|
||||
const entries = Object.entries(pathParams);
|
||||
for (const [key, value] of entries) {
|
||||
if (!Array.isArray(value)) {
|
||||
const matcher = turnValueToRegExp(value);
|
||||
if (matcher.test(result)) {
|
||||
result = result.replace(matcher, `/[${key}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const [key, value] of entries) {
|
||||
if (Array.isArray(value)) {
|
||||
const matcher = turnValueToRegExp(value.join("/"));
|
||||
if (matcher.test(result)) {
|
||||
result = result.replace(matcher, `/[...${key}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch {
|
||||
return pathname;
|
||||
}
|
||||
}
|
||||
function turnValueToRegExp(value) {
|
||||
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
||||
}
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
function getScriptSrc(props) {
|
||||
if (props.scriptSrc) {
|
||||
return makeAbsolute(props.scriptSrc);
|
||||
}
|
||||
if (isDevelopment()) {
|
||||
return "https://va.vercel-scripts.com/v1/script.debug.js";
|
||||
}
|
||||
if (props.basePath) {
|
||||
return makeAbsolute(`${props.basePath}/insights/script.js`);
|
||||
}
|
||||
return "/_vercel/insights/script.js";
|
||||
}
|
||||
function loadProps(explicitProps, confString) {
|
||||
var _a;
|
||||
let props = explicitProps;
|
||||
if (confString) {
|
||||
try {
|
||||
props = {
|
||||
...(_a = JSON.parse(confString)) == null ? void 0 : _a.analytics,
|
||||
...explicitProps
|
||||
};
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
setMode(props.mode);
|
||||
const dataset = {
|
||||
sdkn: name + (props.framework ? `/${props.framework}` : ""),
|
||||
sdkv: version
|
||||
};
|
||||
if (props.disableAutoTrack) {
|
||||
dataset.disableAutoTrack = "1";
|
||||
}
|
||||
if (props.viewEndpoint) {
|
||||
dataset.viewEndpoint = makeAbsolute(props.viewEndpoint);
|
||||
}
|
||||
if (props.eventEndpoint) {
|
||||
dataset.eventEndpoint = makeAbsolute(props.eventEndpoint);
|
||||
}
|
||||
if (props.sessionEndpoint) {
|
||||
dataset.sessionEndpoint = makeAbsolute(props.sessionEndpoint);
|
||||
}
|
||||
if (isDevelopment() && props.debug === false) {
|
||||
dataset.debug = "false";
|
||||
}
|
||||
if (props.dsn) {
|
||||
dataset.dsn = props.dsn;
|
||||
}
|
||||
if (props.endpoint) {
|
||||
dataset.endpoint = props.endpoint;
|
||||
} else if (props.basePath) {
|
||||
dataset.endpoint = makeAbsolute(`${props.basePath}/insights`);
|
||||
}
|
||||
return {
|
||||
beforeSend: props.beforeSend,
|
||||
src: getScriptSrc(props),
|
||||
dataset
|
||||
};
|
||||
}
|
||||
function makeAbsolute(url) {
|
||||
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/") ? url : `/${url}`;
|
||||
}
|
||||
|
||||
// src/generic.ts
|
||||
function inject(props = {
|
||||
debug: true
|
||||
}, confString) {
|
||||
var _a;
|
||||
if (!isBrowser()) return;
|
||||
const { beforeSend, src, dataset } = loadProps(props, confString);
|
||||
initQueue();
|
||||
if (beforeSend) {
|
||||
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
||||
}
|
||||
if (document.head.querySelector(`script[src*="${src}"]`)) return;
|
||||
const script = document.createElement("script");
|
||||
script.src = src;
|
||||
for (const [key, value] of Object.entries(dataset)) {
|
||||
script.dataset[key] = value;
|
||||
}
|
||||
script.defer = true;
|
||||
script.onerror = () => {
|
||||
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.";
|
||||
console.log(
|
||||
`[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`
|
||||
);
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
function pageview({
|
||||
route,
|
||||
path
|
||||
}) {
|
||||
var _a;
|
||||
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", { route, path });
|
||||
}
|
||||
|
||||
// src/vue/utils.ts
|
||||
var import_meta = {};
|
||||
function getBasePath() {
|
||||
try {
|
||||
return import_meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
function getConfigString() {
|
||||
try {
|
||||
return import_meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
|
||||
// src/vue/create-component.ts
|
||||
function createComponent(framework = "vue") {
|
||||
return (0, import_vue.defineComponent)({
|
||||
props: ["dsn", "beforeSend", "debug", "scriptSrc", "endpoint", "mode"],
|
||||
setup(props) {
|
||||
const route = (0, import_vue_router.useRoute)();
|
||||
inject(
|
||||
{
|
||||
// trim out undefined values to avoid overriding config values
|
||||
...Object.fromEntries(
|
||||
Object.entries(props).filter(([_, v]) => v !== void 0)
|
||||
),
|
||||
basePath: getBasePath(),
|
||||
// keep auto-tracking unless we have route support (Nuxt or vue-router).
|
||||
disableAutoTrack: Boolean(route),
|
||||
framework
|
||||
},
|
||||
getConfigString()
|
||||
);
|
||||
if (route && typeof window !== "undefined") {
|
||||
const changeRoute = () => {
|
||||
pageview({
|
||||
route: computeRoute(route.path, route.params),
|
||||
path: route.path
|
||||
});
|
||||
};
|
||||
changeRoute();
|
||||
(0, import_vue.watch)(route, changeRoute);
|
||||
}
|
||||
},
|
||||
// Vue component must have a render function, or a template.
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// src/vue/index.ts
|
||||
var Analytics = createComponent();
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Analytics
|
||||
});
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/vue/index.ts","../../src/vue/create-component.ts","../../src/queue.ts","../../package.json","../../src/utils.ts","../../src/generic.ts","../../src/vue/utils.ts"],"sourcesContent":["import type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { createComponent } from './create-component';\n\nexport const Analytics = createComponent();\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n","import { defineComponent, watch } from 'vue';\n// for barebone vue project, vite will issue a warning since 'vue-router' import can't be resolved,\nimport { useRoute } from 'vue-router';\nimport { type AnalyticsProps, inject, pageview } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function createComponent(\n framework = 'vue',\n): ReturnType<typeof defineComponent> {\n return defineComponent({\n props: ['dsn', 'beforeSend', 'debug', 'scriptSrc', 'endpoint', 'mode'],\n setup(props: Omit<AnalyticsProps, 'framework'>) {\n const route = useRoute();\n inject(\n {\n // trim out undefined values to avoid overriding config values\n ...Object.fromEntries(\n Object.entries(props).filter(([_, v]) => v !== undefined),\n ),\n basePath: getBasePath(),\n // keep auto-tracking unless we have route support (Nuxt or vue-router).\n disableAutoTrack: Boolean(route),\n framework,\n },\n getConfigString(),\n );\n if (route && typeof window !== 'undefined') {\n const changeRoute = (): void => {\n pageview({\n route: computeRoute(route.path, route.params),\n path: route.path,\n });\n };\n changeRoute();\n watch(route, changeRoute);\n }\n },\n // Vue component must have a render function, or a template.\n render() {\n return null;\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 if (!window.vaq) window.vaq = [];\n window.vaq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"2.0.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\": \"MIT\",\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 \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/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.mjs\",\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 \"nuxt/runtime\": [\n \"dist/nuxt/runtime/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\":Line truncated
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
// src/vue/create-component.ts
|
||||
import { defineComponent, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
// src/queue.ts
|
||||
var initQueue = () => {
|
||||
if (window.va) return;
|
||||
window.va = function a(...params) {
|
||||
if (!window.vaq) window.vaq = [];
|
||||
window.vaq.push(params);
|
||||
};
|
||||
};
|
||||
|
||||
// package.json
|
||||
var name = "@vercel/analytics";
|
||||
var version = "2.0.1";
|
||||
|
||||
// src/utils.ts
|
||||
function isBrowser() {
|
||||
return typeof window !== "undefined";
|
||||
}
|
||||
function detectEnvironment() {
|
||||
try {
|
||||
const env = process.env.NODE_ENV;
|
||||
if (env === "development" || env === "test") {
|
||||
return "development";
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return "production";
|
||||
}
|
||||
function setMode(mode = "auto") {
|
||||
if (mode === "auto") {
|
||||
window.vam = detectEnvironment();
|
||||
return;
|
||||
}
|
||||
window.vam = mode;
|
||||
}
|
||||
function getMode() {
|
||||
const mode = isBrowser() ? window.vam : detectEnvironment();
|
||||
return mode || "production";
|
||||
}
|
||||
function isDevelopment() {
|
||||
return getMode() === "development";
|
||||
}
|
||||
function computeRoute(pathname, pathParams) {
|
||||
if (!pathname || !pathParams) {
|
||||
return pathname;
|
||||
}
|
||||
let result = pathname;
|
||||
try {
|
||||
const entries = Object.entries(pathParams);
|
||||
for (const [key, value] of entries) {
|
||||
if (!Array.isArray(value)) {
|
||||
const matcher = turnValueToRegExp(value);
|
||||
if (matcher.test(result)) {
|
||||
result = result.replace(matcher, `/[${key}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const [key, value] of entries) {
|
||||
if (Array.isArray(value)) {
|
||||
const matcher = turnValueToRegExp(value.join("/"));
|
||||
if (matcher.test(result)) {
|
||||
result = result.replace(matcher, `/[...${key}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch {
|
||||
return pathname;
|
||||
}
|
||||
}
|
||||
function turnValueToRegExp(value) {
|
||||
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
||||
}
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
function getScriptSrc(props) {
|
||||
if (props.scriptSrc) {
|
||||
return makeAbsolute(props.scriptSrc);
|
||||
}
|
||||
if (isDevelopment()) {
|
||||
return "https://va.vercel-scripts.com/v1/script.debug.js";
|
||||
}
|
||||
if (props.basePath) {
|
||||
return makeAbsolute(`${props.basePath}/insights/script.js`);
|
||||
}
|
||||
return "/_vercel/insights/script.js";
|
||||
}
|
||||
function loadProps(explicitProps, confString) {
|
||||
var _a;
|
||||
let props = explicitProps;
|
||||
if (confString) {
|
||||
try {
|
||||
props = {
|
||||
...(_a = JSON.parse(confString)) == null ? void 0 : _a.analytics,
|
||||
...explicitProps
|
||||
};
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
setMode(props.mode);
|
||||
const dataset = {
|
||||
sdkn: name + (props.framework ? `/${props.framework}` : ""),
|
||||
sdkv: version
|
||||
};
|
||||
if (props.disableAutoTrack) {
|
||||
dataset.disableAutoTrack = "1";
|
||||
}
|
||||
if (props.viewEndpoint) {
|
||||
dataset.viewEndpoint = makeAbsolute(props.viewEndpoint);
|
||||
}
|
||||
if (props.eventEndpoint) {
|
||||
dataset.eventEndpoint = makeAbsolute(props.eventEndpoint);
|
||||
}
|
||||
if (props.sessionEndpoint) {
|
||||
dataset.sessionEndpoint = makeAbsolute(props.sessionEndpoint);
|
||||
}
|
||||
if (isDevelopment() && props.debug === false) {
|
||||
dataset.debug = "false";
|
||||
}
|
||||
if (props.dsn) {
|
||||
dataset.dsn = props.dsn;
|
||||
}
|
||||
if (props.endpoint) {
|
||||
dataset.endpoint = props.endpoint;
|
||||
} else if (props.basePath) {
|
||||
dataset.endpoint = makeAbsolute(`${props.basePath}/insights`);
|
||||
}
|
||||
return {
|
||||
beforeSend: props.beforeSend,
|
||||
src: getScriptSrc(props),
|
||||
dataset
|
||||
};
|
||||
}
|
||||
function makeAbsolute(url) {
|
||||
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/") ? url : `/${url}`;
|
||||
}
|
||||
|
||||
// src/generic.ts
|
||||
function inject(props = {
|
||||
debug: true
|
||||
}, confString) {
|
||||
var _a;
|
||||
if (!isBrowser()) return;
|
||||
const { beforeSend, src, dataset } = loadProps(props, confString);
|
||||
initQueue();
|
||||
if (beforeSend) {
|
||||
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
||||
}
|
||||
if (document.head.querySelector(`script[src*="${src}"]`)) return;
|
||||
const script = document.createElement("script");
|
||||
script.src = src;
|
||||
for (const [key, value] of Object.entries(dataset)) {
|
||||
script.dataset[key] = value;
|
||||
}
|
||||
script.defer = true;
|
||||
script.onerror = () => {
|
||||
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.";
|
||||
console.log(
|
||||
`[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`
|
||||
);
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
function pageview({
|
||||
route,
|
||||
path
|
||||
}) {
|
||||
var _a;
|
||||
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", { route, path });
|
||||
}
|
||||
|
||||
// src/vue/utils.ts
|
||||
function getBasePath() {
|
||||
try {
|
||||
return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
function getConfigString() {
|
||||
try {
|
||||
return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
|
||||
// src/vue/create-component.ts
|
||||
function createComponent(framework = "vue") {
|
||||
return defineComponent({
|
||||
props: ["dsn", "beforeSend", "debug", "scriptSrc", "endpoint", "mode"],
|
||||
setup(props) {
|
||||
const route = useRoute();
|
||||
inject(
|
||||
{
|
||||
// trim out undefined values to avoid overriding config values
|
||||
...Object.fromEntries(
|
||||
Object.entries(props).filter(([_, v]) => v !== void 0)
|
||||
),
|
||||
basePath: getBasePath(),
|
||||
// keep auto-tracking unless we have route support (Nuxt or vue-router).
|
||||
disableAutoTrack: Boolean(route),
|
||||
framework
|
||||
},
|
||||
getConfigString()
|
||||
);
|
||||
if (route && typeof window !== "undefined") {
|
||||
const changeRoute = () => {
|
||||
pageview({
|
||||
route: computeRoute(route.path, route.params),
|
||||
path: route.path
|
||||
});
|
||||
};
|
||||
changeRoute();
|
||||
watch(route, changeRoute);
|
||||
}
|
||||
},
|
||||
// Vue component must have a render function, or a template.
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// src/vue/index.ts
|
||||
var Analytics = createComponent();
|
||||
export {
|
||||
Analytics
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/vue/create-component.ts","../../src/queue.ts","../../package.json","../../src/utils.ts","../../src/generic.ts","../../src/vue/utils.ts","../../src/vue/index.ts"],"sourcesContent":["import { defineComponent, watch } from 'vue';\n// for barebone vue project, vite will issue a warning since 'vue-router' import can't be resolved,\nimport { useRoute } from 'vue-router';\nimport { type AnalyticsProps, inject, pageview } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function createComponent(\n framework = 'vue',\n): ReturnType<typeof defineComponent> {\n return defineComponent({\n props: ['dsn', 'beforeSend', 'debug', 'scriptSrc', 'endpoint', 'mode'],\n setup(props: Omit<AnalyticsProps, 'framework'>) {\n const route = useRoute();\n inject(\n {\n // trim out undefined values to avoid overriding config values\n ...Object.fromEntries(\n Object.entries(props).filter(([_, v]) => v !== undefined),\n ),\n basePath: getBasePath(),\n // keep auto-tracking unless we have route support (Nuxt or vue-router).\n disableAutoTrack: Boolean(route),\n framework,\n },\n getConfigString(),\n );\n if (route && typeof window !== 'undefined') {\n const changeRoute = (): void => {\n pageview({\n route: computeRoute(route.path, route.params),\n path: route.path,\n });\n };\n changeRoute();\n watch(route, changeRoute);\n }\n },\n // Vue component must have a render function, or a template.\n render() {\n return null;\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 if (!window.vaq) window.vaq = [];\n window.vaq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"2.0.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\": \"MIT\",\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 \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/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.mjs\",\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 \"nuxt/runtime\": [\n \"dist/nuxt/runtime/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 \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^Line truncated
|
||||
Reference in new issue
Block a user