@propertechnologies/espia
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -9,2 +9,3 @@ export interface EspiaSetup { | ||
export declare function setSession(value: string): void; | ||
export declare function setPermanentMetadata(key: string, value: unknown): void; | ||
export declare function track(category: string, metadata?: object, overwrites?: Overwrites): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.track = exports.setSession = exports.espia = void 0; | ||
exports.track = exports.setPermanentMetadata = exports.setSession = exports.espia = void 0; | ||
const BASE = "https://analytics.proper.ai"; | ||
@@ -20,25 +20,41 @@ const EVENT_URL = `${BASE}/events`; | ||
} | ||
let _source; | ||
let _session; | ||
let _enabled = true; | ||
let source; | ||
let session; | ||
let enabled = true; | ||
const metadata = new Map(); | ||
function espia(value) { | ||
var _a; | ||
_source = value.source; | ||
_session = value.session; | ||
_enabled = (_a = value.enabled) !== null && _a !== void 0 ? _a : true; | ||
source = value.source; | ||
session = value.session; | ||
enabled = (_a = value.enabled) !== null && _a !== void 0 ? _a : true; | ||
metadata.clear(); | ||
} | ||
exports.espia = espia; | ||
function setSession(value) { | ||
_session = value; | ||
session = value; | ||
} | ||
exports.setSession = setSession; | ||
function setPermanentMetadata(key, value) { | ||
metadata.set(key, value); | ||
} | ||
exports.setPermanentMetadata = setPermanentMetadata; | ||
function track(category, metadata, overwrites) { | ||
if (!_enabled) { | ||
if (!enabled) { | ||
return; | ||
} | ||
if (_source === undefined && (overwrites === null || overwrites === void 0 ? void 0 : overwrites.source) === undefined) { | ||
if (source === undefined && (overwrites === null || overwrites === void 0 ? void 0 : overwrites.source) === undefined) { | ||
throw new Error("Make sure you init espia with a source before tracking events"); | ||
} | ||
commit((overwrites === null || overwrites === void 0 ? void 0 : overwrites.source) || _source, category, metadata, (overwrites === null || overwrites === void 0 ? void 0 : overwrites.session) || _session); | ||
commit((overwrites === null || overwrites === void 0 ? void 0 : overwrites.source) || source, category, metadataWithPermanent(metadata), (overwrites === null || overwrites === void 0 ? void 0 : overwrites.session) || session); | ||
} | ||
exports.track = track; | ||
function metadataWithPermanent(value) { | ||
if (metadata.size === 0 && value === undefined) { | ||
return undefined; | ||
} | ||
const result = Object.fromEntries(metadata.entries()); | ||
if (value === undefined) { | ||
return result; | ||
} | ||
return Object.assign(Object.assign({}, result), value); | ||
} |
{ | ||
"name": "@propertechnologies/espia", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Typed wrapper around analytics.proper.ai", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
3553
69