@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
67 lines • 1.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.analytics = exports.Analytics = void 0;
const posthog_node_1 = require("posthog-node");
const constants_1 = require("../lib/constants");
const uuid_1 = require("uuid");
class Analytics {
client;
tags = {};
distinctId;
anonymousId;
constructor() {
this.client = new posthog_node_1.PostHog(constants_1.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY, {
host: constants_1.ANALYTICS_HOST_URL,
flushAt: 1,
flushInterval: 0,
enableExceptionAutocapture: true,
});
this.tags = {};
this.anonymousId = (0, uuid_1.v4)();
this.distinctId = undefined;
}
setDistinctId(distinctId) {
this.distinctId = distinctId;
this.client.alias({
distinctId,
alias: this.anonymousId,
});
}
setTag(key, value) {
this.tags[key] = value;
}
captureException(error, properties = {}) {
this.client.captureException(error, this.distinctId ?? this.anonymousId, {
team: 'growth',
...this.tags,
...properties,
});
}
capture(eventName, properties) {
this.client.capture({
distinctId: this.distinctId ?? this.anonymousId,
event: eventName,
properties: {
...this.tags,
...properties,
},
});
}
async shutdown(status) {
if (Object.keys(this.tags).length === 0) {
return;
}
this.client.capture({
distinctId: this.distinctId ?? this.anonymousId,
event: 'setup wizard finished',
properties: {
status,
tags: this.tags,
},
});
await this.client.shutdown();
}
}
exports.Analytics = Analytics;
exports.analytics = new Analytics();
//# sourceMappingURL=analytics.js.map