feat: Setup posthog analytics (#12291)

- Replace June.so analytics with PostHog integration
- Maintain existing analytics API interface for seamless migration
- Remove all the June references

_June.so is shutting down their service, requiring migration to an
alternative analytics provider. PostHog was chosen as the replacement
due to its robust feature set and similar API structure._
This commit is contained in:
Muhsin Keloth
2025-08-27 09:10:06 +05:30
committed by GitHub
parent ad90deb709
commit 068538e3d6
5 changed files with 92 additions and 1363 deletions

View File

@@ -1,4 +1,4 @@
import { AnalyticsBrowser } from '@june-so/analytics-next';
import posthog from 'posthog-js';
/**
* AnalyticsHelper class to initialize and track user analytics
@@ -26,10 +26,12 @@ export class AnalyticsHelper {
return;
}
let [analytics] = await AnalyticsBrowser.load({
writeKey: this.analyticsToken,
posthog.init(this.analyticsToken, {
api_host: 'https://app.posthog.com',
capture_pageview: false,
persistence: 'localStorage+cookie',
});
this.analytics = analytics;
this.analytics = posthog;
}
/**
@@ -43,8 +45,7 @@ export class AnalyticsHelper {
}
this.user = user;
this.analytics.identify(this.user.email, {
userId: this.user.id,
this.analytics.identify(this.user.id.toString(), {
email: this.user.email,
name: this.user.name,
avatar: this.user.avatar_url,
@@ -55,7 +56,7 @@ export class AnalyticsHelper {
account => account.id === accountId
);
if (currentAccount) {
this.analytics.group(currentAccount.id, this.user.id, {
this.analytics.group('company', currentAccount.id.toString(), {
name: currentAccount.name,
});
}
@@ -71,12 +72,7 @@ export class AnalyticsHelper {
if (!this.analytics) {
return;
}
this.analytics.track({
userId: this.user.id,
event: eventName,
properties,
});
this.analytics.capture(eventName, properties);
}
/**
@@ -89,9 +85,9 @@ export class AnalyticsHelper {
return;
}
this.analytics.page(params);
this.analytics.capture('$pageview', params);
}
}
// This object is shared across, the init is called in app/javascript/packs/application.js
// This object is shared across, the init is called in app/javascript/entrypoints/dashboard.js
export default new AnalyticsHelper(window.analyticsConfig);