Skip to content

Commit ff72d7d

Browse files
committed
fix(dashboard): segment alias on new signups
1 parent 21a6d17 commit ff72d7d

File tree

5 files changed

+196
-219
lines changed

5 files changed

+196
-219
lines changed

apps/dashboard/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@rjsf/core": "^5.22.3",
5656
"@rjsf/utils": "^5.20.0",
5757
"@rjsf/validator-ajv8": "^5.17.1",
58-
"@segment/analytics-next": "^1.73.0",
58+
"@segment/analytics-next": "^1.77.0",
5959
"@sentry/react": "^8.35.0",
6060
"@tanstack/react-query": "^5.59.6",
6161
"@tiptap/react": "^2.6.6",

apps/dashboard/src/components/auth/questionnaire-form.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ function useSubmitQuestionnaire() {
262262
});
263263

264264
if (currentUser && currentOrganization) {
265+
const anonymousId = await segment.getAnonymousId();
266+
if (anonymousId) {
267+
segment.alias(anonymousId, currentUser._id);
268+
}
269+
265270
segment.identify(currentUser, {
266271
organizationType: data.organizationType,
267272
jobTitle: data.jobTitle,

apps/dashboard/src/pages/workflows.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,8 @@ export const WorkflowsPage = () => {
177177
navigate(buildRoute(ROUTES.WORKFLOWS_CREATE, { environmentSlug: environmentSlug || '' }));
178178
}}
179179
>
180-
<div className="flex items-center gap-2">
181-
<RiFileAddLine />
182-
Blank Workflow
183-
</div>
180+
<RiFileAddLine />
181+
Blank Workflow
184182
</div>
185183
</DropdownMenuItem>
186184
<DropdownMenuItem

apps/dashboard/src/utils/segment.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { AnalyticsBrowser } from '@segment/analytics-next';
2-
import type { IUserEntity } from '@novu/shared';
3-
import * as mixpanel from 'mixpanel-browser';
41
import { MIXPANEL_KEY, SEGMENT_KEY } from '@/config';
2+
import type { IUserEntity } from '@novu/shared';
3+
import { AnalyticsBrowser } from '@segment/analytics-next';
54
import * as Sentry from '@sentry/react';
5+
import * as mixpanel from 'mixpanel-browser';
66
export class SegmentService {
77
private _segment: AnalyticsBrowser | null = null;
88
private _segmentEnabled: boolean;
@@ -146,6 +146,16 @@ export class SegmentService {
146146
this._segment?.reset();
147147
}
148148

149+
async getAnonymousId() {
150+
if (!this.isSegmentEnabled()) {
151+
return;
152+
}
153+
154+
const user = await this._segment?.user();
155+
156+
return user?.anonymousId();
157+
}
158+
149159
isSegmentEnabled(): boolean {
150160
return this._segmentEnabled && this._segment !== null && typeof window !== 'undefined';
151161
}

0 commit comments

Comments
 (0)