posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

Events are triggered twice with Segment integration

Open sangaline opened this issue 1 year ago • 0 comments

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.

sangaline avatar Sep 13 '24 13:09 sangaline