@hackthenorth/analytics
Advanced tools
Comparing version 0.0.5 to 0.0.7
declare type LogEntry = { | ||
key: string; | ||
identifier: string; | ||
duration: number; | ||
}; | ||
declare type Config = { | ||
url: string; | ||
bufferSize: number; | ||
uuid: string; | ||
}; | ||
export declare function logImmediate(data: LogEntry): void; | ||
export declare function log(data: LogEntry): void; | ||
export declare function configureAnalyticsLogger(config: Partial<Config>): void; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.log = exports.logImmediate = void 0; | ||
exports.configureAnalyticsLogger = exports.log = exports.logImmediate = void 0; | ||
const uuid_1 = require("uuid"); | ||
const defaults = { | ||
url: "https://api.hackthenorth.com/v3/injest", | ||
url: "https://api.hackthenorth.com/ingest", | ||
bufferSize: 10, | ||
uid: uuid_1.v4(), | ||
uuid: uuid_1.v4(), | ||
}; | ||
@@ -20,6 +20,9 @@ class BatchedLogger { | ||
} | ||
configure(config) { | ||
this.config = Object.assign(Object.assign({}, this.config), config); | ||
} | ||
encodeAndSend(data) { | ||
if (this.toLog.length > 0) { | ||
navigator.sendBeacon(this.config.url, JSON.stringify({ | ||
uid: this.config.uid, | ||
navigator.sendBeacon("url", JSON.stringify({ | ||
uid: this.config.uuid, | ||
data: data !== null && data !== void 0 ? data : this.toLog, | ||
@@ -49,1 +52,5 @@ })); | ||
exports.log = log; | ||
function configureAnalyticsLogger(config) { | ||
return BatchedLoggerInstance.configure(config); | ||
} | ||
exports.configureAnalyticsLogger = configureAnalyticsLogger; |
declare class Span { | ||
startTime: number; | ||
elapsed: number; | ||
key: string; | ||
identifier: string; | ||
isOpen: boolean; | ||
constructor(key: string); | ||
constructor(identifier: string); | ||
end(): number; | ||
@@ -8,0 +8,0 @@ } |
@@ -6,6 +6,6 @@ "use strict"; | ||
class Span { | ||
constructor(key) { | ||
constructor(identifier) { | ||
this.startTime = Date.now(); | ||
this.isOpen = true; | ||
this.key = key; | ||
this.identifier = identifier; | ||
} | ||
@@ -25,4 +25,4 @@ end() { | ||
const duration = span.end(); | ||
return logger_1.log({ key: span.key, duration }); | ||
return logger_1.log({ identifier: span.identifier, duration }); | ||
} | ||
exports.endSpan = endSpan; |
{ | ||
"name": "@hackthenorth/analytics", | ||
"version": "0.0.5", | ||
"version": "0.0.7", | ||
"description": "", | ||
@@ -8,2 +8,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -10,0 +11,0 @@ }, |
9524
241