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

@databeat/tracker

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@databeat/tracker - npm Package Compare versions

Comparing version 0.3.7 to 0.4.0

20

dist/databeat-tracker.d.ts

@@ -9,3 +9,4 @@ declare enum EventType {

source?: string;
session?: string;
userId?: string;
sessionId?: string;
device?: Device;

@@ -16,3 +17,3 @@ countryCode?: string;

};
vals?: {
nums?: {
[key: string]: number;

@@ -34,3 +35,3 @@ };

defaultEnabled?: boolean;
sessionIds?: sessionOptions;
userId?: userOptions;
flushInterval?: number;

@@ -43,2 +44,3 @@ initProps?: () => {};

private enabled;
private userId;
private sessionId;

@@ -53,3 +55,3 @@ private queue;

reset(): void;
session(sessionId?: string, options?: sessionOptions): void;
user(userId?: string, options?: userOptions): void;
track(events: Event<K> | Event<K>[], options?: {

@@ -64,2 +66,3 @@ flush?: boolean;

isAnon(): boolean;
getUserId(): string;
getSessionId(): string;

@@ -75,8 +78,9 @@ enable(): void;

declare const getStorageVal: () => StorageVal | null;
interface sessionOptions {
interface userOptions {
hash: boolean;
agentSalt?: boolean;
userAgentSalt?: boolean;
}
declare const genSessionId: (seed: string, options?: sessionOptions) => string;
declare const genUserId: (seed: string, options?: userOptions) => string;
declare const genSessionId: () => string;
export { Databeat, DatabeatOptions, Event, genSessionId, getStorageVal };
export { Databeat, DatabeatOptions, Event, genSessionId, genUserId, getStorageVal };

78

dist/databeat-tracker.js

@@ -120,3 +120,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class; var _class2; var _class3;// src/rpc/proto/databeat.gen.ts

defaultEnabled: true,
sessionIds: { hash: true, agentSalt: true },
userId: { hash: true, userAgentSalt: true },
initProps: () => {

@@ -136,2 +136,3 @@ return {};

constructor(host, authToken, options) {;_class3.prototype.__init8.call(this);

@@ -145,3 +146,3 @@ this.authToken = authToken;

defaultEnabled: options.defaultEnabled || defaultDatabeatOptions.defaultEnabled,
sessionIds: options.sessionIds || defaultDatabeatOptions.sessionIds,
userId: options.userId || defaultDatabeatOptions.userId,
initProps: options.initProps || defaultDatabeatOptions.initProps

@@ -154,31 +155,32 @@ };

this.enabled = isEnabled(this.options.defaultEnabled, this.authToken);
this.sessionId = null;
this.userId = null;
this.sessionId = genSessionId();
this.queue = [];
this.flushTimeout = null;
this.defaultProps = { ...getUrlQueryProps(), ...this.options.initProps() };
this.session();
this.user();
}
reset() {
this.enabled = isEnabled(this.options.defaultEnabled, this.authToken);
if (this.sessionId && !this.sessionId.startsWith("anon:")) {
this.sessionId = null;
if (this.userId && !this.userId.startsWith("anon:")) {
this.userId = null;
}
setStorageVal({ on: this.enabled, id: this.sessionId });
setStorageVal({ on: this.enabled, id: this.userId });
this.init();
}
session(sessionId, options) {
user(userId, options) {
if (!isBrowser())
return;
if (!sessionId) {
if (!userId) {
const val = getStorageVal();
if (val !== null && val.id !== null) {
this.sessionId = val.id;
this.userId = val.id;
}
}
if (sessionId || this.sessionId === null) {
this.sessionId = genSessionId(sessionId, options || this.options.sessionIds);
setStorageVal({ on: this.enabled, id: this.sessionId });
if (userId || this.userId === null) {
this.userId = genUserId(userId, options || this.options.userId);
setStorageVal({ on: this.enabled, id: this.userId });
}
if (this.enabled) {
this.track({ event: "INIT", source: getPagePath(), session: this.sessionId, props: this.defaultProps });
this.track({ event: "INIT", source: getPagePath(), props: this.defaultProps });
this.flush();

@@ -190,3 +192,3 @@ }

return;
if (isBrowser() && this.sessionId === null) {
if (isBrowser() && this.userId === null) {
throw new Error("init first");

@@ -197,3 +199,4 @@ }

for (let i = 0; i < events.length; i++) {
events[i].session = this.sessionId;
events[i].userId = this.userId;
events[i].sessionId = this.sessionId;
if (isAnon) {

@@ -207,3 +210,4 @@ if (!events[i].props)

} else {
events.session = this.sessionId;
events.userId = this.userId;
events.sessionId = this.sessionId;
if (isAnon) {

@@ -227,3 +231,3 @@ if (!events.props)

const eventSource = getPagePath();
const pageKey = `${eventSource}:${JSON.stringify(eventProps)}:${this.sessionId}`;
const pageKey = `${eventSource}:${JSON.stringify(eventProps)}:${this.userId}:${this.sessionId}`;
if (this.previousPageKey === pageKey)

@@ -253,4 +257,7 @@ return;

isAnon() {
return this.sessionId && this.sessionId.startsWith("anon:");
return this.userId && this.userId.startsWith("anon:");
}
getUserId() {
return this.userId;
}
getSessionId() {

@@ -269,3 +276,3 @@ return this.sessionId;

this.enabled = true;
this.session();
this.user();
}

@@ -276,3 +283,3 @@ disable() {

this.enabled = false;
setStorageVal({ on: this.enabled, id: this.sessionId });
setStorageVal({ on: this.enabled, id: this.userId });
}

@@ -357,3 +364,3 @@ }, _class3);

};
var genSessionId = (seed, options = { hash: true, agentSalt: true }) => {
var genUserId = (seed, options = { hash: true, userAgentSalt: true }) => {
if (!seed || seed === null || seed === "") {

@@ -364,3 +371,3 @@ const id = Math.floor(Math.random() * 1e11);

if (options.hash) {
if (isBrowser() && options.agentSalt === true) {
if (isBrowser() && options.userAgentSalt === true) {
seed = seed + ":" + navigator.userAgent;

@@ -373,2 +380,24 @@ }

};
var genSessionId = () => {
const isSessionStorageAvail = isBrowser() && typeof window.sessionStorage === "object" && typeof window.sessionStorage.getItem === "function" && typeof window.sessionStorage.setItem === "function";
if (!isSessionStorageAvail) {
return genRandHex(16);
} else {
const sid = window.sessionStorage.getItem(storageKey);
if (!!sid && sid.length > 0) {
return sid;
} else {
const sid2 = genRandHex(16);
window.sessionStorage.setItem(storageKey, sid2);
return sid2;
}
}
};
var genRandHex = (n) => {
let hexString = "";
for (let i = 0; i < n; i++) {
hexString += Math.floor(Math.random() * 16).toString(16);
}
return "0x" + hexString;
};
if (typeof process === "object" && process.version && process.version < "v18") {

@@ -384,3 +413,4 @@ console.error(`ERROR! expecting node v18+ but your node version is reporting ${process.version}`);

exports.Databeat = Databeat2; exports.genSessionId = genSessionId; exports.getStorageVal = getStorageVal;
exports.Databeat = Databeat2; exports.genSessionId = genSessionId; exports.genUserId = genUserId; exports.getStorageVal = getStorageVal;
//# sourceMappingURL=databeat-tracker.js.map
{
"name": "@databeat/tracker",
"version": "0.3.7",
"version": "0.4.0",
"description": "databeat tracker client for Web browsers and node.js",
"main": "dist/databeat-tracker.cjs",
"module": "dist/databeat-tracker.js",
"main": "dist/databeat-tracker.js",
"module": "dist/databeat-tracker.mjs",
"types": "dist/databeat-tracker.d.ts",

@@ -23,4 +23,3 @@ "typings": "dist/databeat-tracker.d.ts",

"types": "./dist/databeat-tracker.d.ts",
"require": "./dist/databeat-tracker.cjs",
"import": "./dist/databeat-tracker.js",
"import": "./dist/databeat-tracker.mjs",
"default": "./dist/databeat-tracker.js"

@@ -34,19 +33,7 @@ },

"devDependencies": {
"@types/node": "^20.3.3",
"@types/node": "^20.4.1",
"rimraf": "^5.0.1",
"tsup": "^7.1.0",
"typescript": "^5.1.6"
},
"tsup": {
"entry": {
"databeat-tracker": "src/index.ts"
},
"format": ["esm","cjs"],
"dts": {
"resolve": true
},
"splitting": true,
"clean": true,
"sourcemap": true
}
}
}

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