MCPcopy Create free account
hub / github.com/winfunc/opcode / initializePostHog

Method initializePostHog

src/lib/analytics/index.ts:67–105  ·  view source on GitHub ↗
(settings: AnalyticsSettings)

Source from the content-addressed store, hash-verified

65 }
66
67 private initializePostHog(settings: AnalyticsSettings): void {
68 try {
69 posthog.init(this.config.apiKey, {
70 api_host: this.config.apiHost,
71 capture_pageview: false, // Disable automatic pageview capture
72 capture_pageleave: false, // Disable automatic pageleave
73 bootstrap: {
74 distinctID: settings.userId,
75 },
76 persistence: this.config.persistence,
77 autocapture: this.config.autocapture,
78 disable_session_recording: this.config.disable_session_recording,
79 opt_out_capturing_by_default: this.config.opt_out_capturing_by_default,
80 loaded: (ph) => {
81 // Set user properties
82 ph.identify(settings.userId, {
83 anonymous: true,
84 consent_date: settings.consentDate,
85 app_type: 'desktop',
86 app_name: 'opcode',
87 });
88
89 // Set initial screen
90 ph.capture('$screen', {
91 $screen_name: 'app_start',
92 });
93
94 // Opt in since user has consented
95 ph.opt_in_capturing();
96
97 if (this.config.loaded) {
98 this.config.loaded(ph);
99 }
100 },
101 });
102 } catch (error) {
103 console.error('Failed to initialize PostHog:', error);
104 }
105 }
106
107 async enable(): Promise<void> {
108 await this.consentManager.grantConsent();

Callers 2

initializeMethod · 0.95
enableMethod · 0.95

Calls 1

identifyMethod · 0.80

Tested by

no test coverage detected