@vercel/analytics
Advanced tools
Comparing version 0.1.8-beta.0 to 0.1.8
@@ -7,3 +7,2 @@ interface PageViewEvent { | ||
declare type Mode = 'auto' | 'development' | 'production'; | ||
declare type AllowedPropertyValues = string | number | boolean | null; | ||
declare type BeforeSend = (event: Event) => Event | null; | ||
@@ -20,3 +19,2 @@ interface AnalyticsProps { | ||
vai?: boolean; | ||
vam?: Mode; | ||
} | ||
@@ -26,4 +24,3 @@ } | ||
declare const inject: (props?: AnalyticsProps) => void; | ||
declare const track: (name: string, properties?: Record<string, AllowedPropertyValues>) => void; | ||
export { inject, track }; | ||
export { inject }; |
@@ -14,47 +14,13 @@ // src/queue.ts | ||
} | ||
function detectEnvironment() { | ||
function isDevelopment() { | ||
if (typeof process === "undefined") | ||
return "production"; | ||
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") | ||
return "development"; | ||
return "production"; | ||
return false; | ||
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test"; | ||
} | ||
function setMode(mode = "auto") { | ||
function getMode(mode = "auto") { | ||
if (mode === "auto") { | ||
window.vam = detectEnvironment(); | ||
return; | ||
return isDevelopment() ? "development" : "production"; | ||
} | ||
window.vam = mode; | ||
return mode; | ||
} | ||
function getMode() { | ||
return window.vam || "production"; | ||
} | ||
function isProduction() { | ||
return getMode() === "production"; | ||
} | ||
function isDevelopment() { | ||
return getMode() === "development"; | ||
} | ||
var removeKey = (key, { [key]: _, ...rest }) => rest; | ||
function parseProperties(properties, options) { | ||
let props = properties; | ||
const errorProperties = []; | ||
for (const [key, value] of Object.entries(properties)) { | ||
if (typeof value === "object" && value !== null) { | ||
if (options.strip) { | ||
props = removeKey(key, props); | ||
} else { | ||
errorProperties.push(key); | ||
} | ||
} | ||
} | ||
if (errorProperties.length > 0 && !options.strip) { | ||
throw Error( | ||
`The following properties are not valid: ${errorProperties.join( | ||
", " | ||
)}. Only strings, numbers, booleans, and null are allowed.` | ||
); | ||
} | ||
return props; | ||
} | ||
@@ -68,3 +34,3 @@ // src/generic.ts | ||
return; | ||
setMode(props.mode); | ||
const mode = getMode(props.mode); | ||
initQueue(); | ||
@@ -74,3 +40,3 @@ if (props.beforeSend) { | ||
} | ||
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js"; | ||
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js"; | ||
if (document.head.querySelector(`script[src*="${src}"]`)) | ||
@@ -81,3 +47,3 @@ return; | ||
script.defer = true; | ||
if (isDevelopment() && props.debug === false) { | ||
if (mode === "development" && props.debug === false) { | ||
script.setAttribute("data-debug", "false"); | ||
@@ -87,26 +53,5 @@ } | ||
}; | ||
var track = (name, properties) => { | ||
var _a, _b; | ||
if (!properties) { | ||
(_a = window.va) == null ? void 0 : _a.call(window, "track", { name }); | ||
return; | ||
} | ||
try { | ||
const props = parseProperties(properties, { | ||
strip: isProduction() | ||
}); | ||
(_b = window.va) == null ? void 0 : _b.call(window, "track", { | ||
name, | ||
data: props | ||
}); | ||
} catch (err) { | ||
if (err instanceof Error && isDevelopment()) { | ||
console.error(err); | ||
} | ||
} | ||
}; | ||
export { | ||
inject, | ||
track | ||
inject | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -7,3 +7,2 @@ interface PageViewEvent { | ||
declare type Mode = 'auto' | 'development' | 'production'; | ||
declare type AllowedPropertyValues = string | number | boolean | null; | ||
declare type BeforeSend = (event: Event) => Event | null; | ||
@@ -20,10 +19,7 @@ interface AnalyticsProps { | ||
vai?: boolean; | ||
vam?: Mode; | ||
} | ||
} | ||
declare const track: (name: string, properties?: Record<string, AllowedPropertyValues>) => void; | ||
declare function Analytics({ beforeSend, debug, mode, }: AnalyticsProps): null; | ||
export { Analytics, AnalyticsProps, track }; | ||
export { Analytics, AnalyticsProps }; |
@@ -17,47 +17,13 @@ // src/react.tsx | ||
} | ||
function detectEnvironment() { | ||
function isDevelopment() { | ||
if (typeof process === "undefined") | ||
return "production"; | ||
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") | ||
return "development"; | ||
return "production"; | ||
return false; | ||
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test"; | ||
} | ||
function setMode(mode = "auto") { | ||
function getMode(mode = "auto") { | ||
if (mode === "auto") { | ||
window.vam = detectEnvironment(); | ||
return; | ||
return isDevelopment() ? "development" : "production"; | ||
} | ||
window.vam = mode; | ||
return mode; | ||
} | ||
function getMode() { | ||
return window.vam || "production"; | ||
} | ||
function isProduction() { | ||
return getMode() === "production"; | ||
} | ||
function isDevelopment() { | ||
return getMode() === "development"; | ||
} | ||
var removeKey = (key, { [key]: _, ...rest }) => rest; | ||
function parseProperties(properties, options) { | ||
let props = properties; | ||
const errorProperties = []; | ||
for (const [key, value] of Object.entries(properties)) { | ||
if (typeof value === "object" && value !== null) { | ||
if (options.strip) { | ||
props = removeKey(key, props); | ||
} else { | ||
errorProperties.push(key); | ||
} | ||
} | ||
} | ||
if (errorProperties.length > 0 && !options.strip) { | ||
throw Error( | ||
`The following properties are not valid: ${errorProperties.join( | ||
", " | ||
)}. Only strings, numbers, booleans, and null are allowed.` | ||
); | ||
} | ||
return props; | ||
} | ||
@@ -71,3 +37,3 @@ // src/generic.ts | ||
return; | ||
setMode(props.mode); | ||
const mode = getMode(props.mode); | ||
initQueue(); | ||
@@ -77,3 +43,3 @@ if (props.beforeSend) { | ||
} | ||
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js"; | ||
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js"; | ||
if (document.head.querySelector(`script[src*="${src}"]`)) | ||
@@ -84,3 +50,3 @@ return; | ||
script.defer = true; | ||
if (isDevelopment() && props.debug === false) { | ||
if (mode === "development" && props.debug === false) { | ||
script.setAttribute("data-debug", "false"); | ||
@@ -90,22 +56,2 @@ } | ||
}; | ||
var track = (name, properties) => { | ||
var _a, _b; | ||
if (!properties) { | ||
(_a = window.va) == null ? void 0 : _a.call(window, "track", { name }); | ||
return; | ||
} | ||
try { | ||
const props = parseProperties(properties, { | ||
strip: isProduction() | ||
}); | ||
(_b = window.va) == null ? void 0 : _b.call(window, "track", { | ||
name, | ||
data: props | ||
}); | ||
} catch (err) { | ||
if (err instanceof Error && isDevelopment()) { | ||
console.error(err); | ||
} | ||
} | ||
}; | ||
@@ -124,5 +70,4 @@ // src/react.tsx | ||
export { | ||
Analytics, | ||
track | ||
Analytics | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@vercel/analytics", | ||
"version": "0.1.8-beta.0", | ||
"version": "0.1.8", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "analytics", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41206
358