Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vercel/analytics

Package Overview
Dependencies
Maintainers
8
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/analytics - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9-beta.0

5

dist/index.d.ts

@@ -7,2 +7,3 @@ interface PageViewEvent {

declare type Mode = 'auto' | 'development' | 'production';
declare type AllowedPropertyValues = string | number | boolean | null;
declare type BeforeSend = (event: Event) => Event | null;

@@ -19,2 +20,3 @@ interface AnalyticsProps {

vai?: boolean;
vam?: Mode;
}

@@ -24,3 +26,4 @@ }

declare const inject: (props?: AnalyticsProps) => void;
declare const track: (name: string, properties?: Record<string, AllowedPropertyValues>) => void;
export { inject };
export { inject, track };

75

dist/index.js

@@ -14,13 +14,47 @@ // src/queue.ts

}
function isDevelopment() {
function detectEnvironment() {
if (typeof process === "undefined")
return false;
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
return "production";
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")
return "development";
return "production";
}
function getMode(mode = "auto") {
function setMode(mode = "auto") {
if (mode === "auto") {
return isDevelopment() ? "development" : "production";
window.vam = detectEnvironment();
return;
}
return mode;
window.vam = 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;
}

@@ -34,3 +68,3 @@ // src/generic.ts

return;
const mode = getMode(props.mode);
setMode(props.mode);
initQueue();

@@ -40,3 +74,3 @@ if (props.beforeSend) {

}
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
if (document.head.querySelector(`script[src*="${src}"]`))

@@ -47,3 +81,3 @@ return;

script.defer = true;
if (mode === "development" && props.debug === false) {
if (isDevelopment() && props.debug === false) {
script.setAttribute("data-debug", "false");

@@ -53,5 +87,26 @@ }

};
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
inject,
track
};
//# sourceMappingURL=index.js.map

@@ -7,2 +7,3 @@ interface PageViewEvent {

declare type Mode = 'auto' | 'development' | 'production';
declare type AllowedPropertyValues = string | number | boolean | null;
declare type BeforeSend = (event: Event) => Event | null;

@@ -19,7 +20,10 @@ 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 };
export { Analytics, AnalyticsProps, track };

@@ -17,13 +17,47 @@ // src/react.tsx

}
function isDevelopment() {
function detectEnvironment() {
if (typeof process === "undefined")
return false;
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
return "production";
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")
return "development";
return "production";
}
function getMode(mode = "auto") {
function setMode(mode = "auto") {
if (mode === "auto") {
return isDevelopment() ? "development" : "production";
window.vam = detectEnvironment();
return;
}
return mode;
window.vam = 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;
}

@@ -37,3 +71,3 @@ // src/generic.ts

return;
const mode = getMode(props.mode);
setMode(props.mode);
initQueue();

@@ -43,3 +77,3 @@ if (props.beforeSend) {

}
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
if (document.head.querySelector(`script[src*="${src}"]`))

@@ -50,3 +84,3 @@ return;

script.defer = true;
if (mode === "development" && props.debug === false) {
if (isDevelopment() && props.debug === false) {
script.setAttribute("data-debug", "false");

@@ -56,2 +90,22 @@ }

};
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);
}
}
};

@@ -70,4 +124,5 @@ // src/react.tsx

export {
Analytics
Analytics,
track
};
//# sourceMappingURL=index.js.map
{
"name": "@vercel/analytics",
"version": "0.1.8",
"version": "0.1.9-beta.0",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc