PostHog / posthog-js

Send usage data from your web app or site to PostHog, with autocapture.
https://posthog.com/docs/libraries/js
Other
299 stars 125 forks source link

Events are triggered twice with Segment integration #1415

Open sangaline opened 2 months ago

sangaline commented 2 months ago

I'm initializing Segment and PostHog like so:

import { AnalyticsBrowser } from '@segment/analytics-next';
import posthog from 'posthog-js';

// Initialize Segment.
const analytics = AnalyticsBrowser.load({
  writeKey: segmentKey,
});

// Initialize PostHog.
analytics.ready(() => {
  posthog.init(posthogKey, {
    api_host: 'https://us.i.posthog.com',
    capture_pageview: false,
    person_profiles: 'always',
    segment: analytics as any,
  });
});

When I do this, the Segment integration works as expected but events that are reported directly through PostHog are triggered twice (e.g. "clicked span," "typed something into input"). The network requests that are being made to PostHog include a mix of ver=1.161.3 and ver=1.160.0 which I think points towards the installed posthog-js version and the one loaded by the Segment integration both sending these events. The installed version of posthog-js is v1.160.0, so the newer version must be loaded by the integration.