mp-lens
Version:
微信小程序分析工具 (Unused Code, Dependencies, Visualization)
29 lines • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendToPostHog = sendToPostHog;
exports.shutdownTelemetry = shutdownTelemetry;
const posthog_node_1 = require("posthog-node");
const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || 'phc_AmH9qDDxzIvq2suq1upLi5tmDF0P6AhRFZKtavIpUof'; // 推荐用环境变量
const POSTHOG_HOST = process.env.POSTHOG_HOST || 'https://us.i.posthog.com';
const client = new posthog_node_1.PostHog(POSTHOG_API_KEY, { host: POSTHOG_HOST });
// 开启调试模式
// client.debug();
client.on('error', (err) => {
console.error('PostHog had an error!', err);
});
function sendToPostHog(event) {
try {
client.capture({
distinctId: event.distinctId,
event: event.event,
properties: event.properties || {},
});
}
catch (e) {
console.error('PostHog capture error:', e);
}
}
async function shutdownTelemetry() {
await client.shutdown();
}
//# sourceMappingURL=posthog.js.map