Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also call posthog.identify with segment #10316

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions contents/docs/libraries/segment.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ The simple Segment destination only supports tracking of pageviews, custom event
analytics.load("<your-segment-key>");

analytics.ready(() => {
window.posthog.init("<your-posthog-key>", {
window.posthog.init("<ph_project_api_key>", {
api_host: '<ph_client_api_host>', // Use eu.i.posthog.com for EU instances
segment: window.analytics, // Pass window.analytics here - NOTE: `window.` is important
capture_pageview: false, // You want this false if you are going to use segment's `analytics.page()` for pageviews
// When the posthog library has loaded, call `analytics.page()` explicitly.
loaded: () => window.analytics.page(),

loaded: (posthog) => {
// When the posthog library has loaded, call `analytics.page()` explicitly.
window.analytics.page()
// If you're calling analytics.identify, you still need to call posthog.identify too
// posthog.identify('[user unique id]')
}
});
})
```
Expand All @@ -70,7 +75,7 @@ Similarly, the `analytics.page()` function sends `$pageview` events and the `ana

### Identifying users

To add identify users and add person properties, you can use Segment's `identify` function:
To add identify users and add person properties, you can use Segment's `identify` function.

```js
analytics.identify('userId123', {
Expand All @@ -83,6 +88,8 @@ This works similarly to PostHog's [`identify` function](/docs/product-analytics/
1. It identifies anonymous users with a distinct ID, creating a person in PostHog.
2. It sets the person properties.

> If you're also using the PostHog SDK or snippet for the other PostHog functionality, you also need to call `posthog.identify`

### Aliasing users

You can also assign multiple distinct IDs to the same user using Segment's `alias` function (the `previousId` argument is optional):
Expand Down
Loading