Skip to content

Commit

Permalink
Ensures the anonymous ID is passed along to analytics (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushchris authored Mar 24, 2024
1 parent 34e5f34 commit 29a276a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apps/platform/src/providers/analytics/AnalyticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import Provider, { ProviderGroup } from '../Provider'

export type AnalyticsProviderName = 'segment' | 'mixpanel' | 'posthog'

export type AnalyticsUserEvent = UserEventParams & { external_id: string }
export type AnalyticsUserEvent = UserEventParams & {
external_id: string
anonymous_id?: string
}

export type Convention = 'snake_case' | 'camel_case' | 'title_case'

Expand Down
1 change: 1 addition & 0 deletions apps/platform/src/providers/analytics/SegmentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class SegmentAnalyticsProvider extends AnalyticsProvider {

this.segment.track({
userId: event.external_id,
anonymousId: event.anonymous_id,
event: this.tranformEventName(event.name, this.event_name_convention),
properties: event.data,
})
Expand Down
1 change: 1 addition & 0 deletions apps/platform/src/users/UserEventRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const createEvent = async (
const analytics = await loadAnalytics(user.project_id)
analytics.track({
external_id: user.external_id,
anonymous_id: user.anonymous_id,
name,
data: filter(data),
})
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/src/users/UserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const createUser = async (projectId: number, { external_id, anonymous_id,
await createEvent(user, {
name: 'user_created',
data: { ...fields, data, external_id, anonymous_id },
})
}, false)

return user
}
Expand Down

0 comments on commit 29a276a

Please sign in to comment.