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

feat streamline journey #834

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test": "cross-env TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit"
},
"dependencies": {
"@amplitude/analytics-node": "^1.3.6",
"@impler/client": "workspace:^",
"@impler/dal": "workspace:^",
"@impler/services": "workspace:^",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/review/review.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { SharedModule } from '@shared/shared.module';
import { AJVService } from './service/AJV.service';
import { Sandbox, SManager } from '../shared/services/sandbox';
import { QueueService } from '@shared/services/queue.service';
import { AmplitudeService } from '@shared/services/amplitude.service';

@Module({
imports: [SharedModule],
providers: [...USE_CASES, AJVService, QueueService, SManager, Sandbox],
providers: [...USE_CASES, AJVService, QueueService, SManager, Sandbox, AmplitudeService],
controllers: [ReviewController],
})
export class ReviewModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@impler/shared';
import { PaymentAPIService } from '@impler/services';
import { QueueService } from '@shared/services/queue.service';
import { AmplitudeService } from '@shared/services/amplitude.service';
import { DalService, TemplateEntity, UploadRepository } from '@impler/dal';

@Injectable()
Expand All @@ -18,6 +19,7 @@ export class StartProcess {
private dalService: DalService,
private queueService: QueueService,
private uploadRepository: UploadRepository,
private amplitudeService: AmplitudeService,
private paymentAPIService: PaymentAPIService
) {}

Expand Down Expand Up @@ -58,6 +60,12 @@ export class StartProcess {
);
}

this.amplitudeService.recordsImported(userEmail, {
records: uploadInfo.totalRecords,
valid: uploadInfo.validRecords,
invalid: uploadInfo.invalidRecords,
});

this.queueService.publishToQueue(QueuesEnum.END_IMPORT, {
uploadId: _uploadId,
destination: destination,
Expand Down
18 changes: 18 additions & 0 deletions apps/api/src/app/shared/services/amplitude.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from '@nestjs/common';
import { init, track } from '@amplitude/analytics-node';

@Injectable()
export class AmplitudeService {
constructor() {
if (process.env.AMPLITUDE_ID) {
init(process.env.AMPLITUDE_ID);
}
}
recordsImported(email: string, data: { records: number; valid: number; invalid: number }) {
if (process.env.AMPLITUDE_ID) {
track('RECORDS IMPORTED', data, {
user_id: email,
});
}
}
}
2 changes: 2 additions & 0 deletions apps/api/src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ declare namespace NodeJS {
PAYMENT_API_BASE_URL: string;
PAYMENT_AUTH_KEY: string;
PAYMENT_AUTH_VALUE: string;

AMPLITUDE_ID: string;
}
}
26 changes: 24 additions & 2 deletions apps/web/components/Integration/IntegrationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import getConfig from 'next/config';
import { useEffect, useState } from 'react';
import { Flex, Title, useMantineColorScheme } from '@mantine/core';

import { colors } from '@config';
import { track } from '@libs/amplitude';
import { IntegrationEnum } from '@impler/shared';
import { IntegrationTabs } from './IntegrationTabs';
import { integrationData } from './IntegrationData';
Expand All @@ -27,6 +29,26 @@ export function IntegrationModal({ accessToken, projectId, templateId, integrati
setSelectedTab(Object.keys(integrationData[integration])[0]);
}, [integration]);

const onIntegrationFrameworkChange = (value: string) => {
track({
name: 'CHANGE INTEGRATION FRAMEWORK',
properties: {
framework: value,
},
});
setIntegration(value as IntegrationEnum);
};

const onIntegrationStepChange = (newStep: string) => {
track({
name: 'CHANGE INTEGRATION STEPS',
properties: {
step: newStep,
},
});
setSelectedTab(newStep);
};

const tabs = Object.keys(integrationData[integration]);

return (
Expand All @@ -35,12 +57,12 @@ export function IntegrationModal({ accessToken, projectId, templateId, integrati
<Title order={3} color={colorScheme === 'dark' ? colors.StrokeLight : colors.black}>
Integrate
</Title>
<IntegrationSelector integration={integration} setIntegration={setIntegration} />
<IntegrationSelector integration={integration} setIntegration={onIntegrationFrameworkChange} />
</Flex>

<IntegrationTabs
value={selectedTab}
onTabChange={setSelectedTab}
onTabChange={onIntegrationStepChange}
items={tabs.map((tab) => ({
id: tab.toLowerCase().replace(/\s+/g, ''),
value: tab,
Expand Down
4 changes: 4 additions & 0 deletions apps/web/hooks/useImportDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export function useImportDetails({ templateId }: useImportDetailProps) {
};

const onIntegrationClick = () => {
track({
name: 'INTEGRATE',
properties: {},
});
if (templateData && profileInfo) {
modals.open({
modalId: MODAL_KEYS.INTEGRATION_DETAILS,
Expand Down
4 changes: 3 additions & 1 deletion apps/web/hooks/useImports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function useImports() {
]);
track({
name: 'IMPORT CREATE',
properties: {},
properties: {
framework: data.integration,
},
});
push(`/imports/${data._id}`);
notify(NOTIFICATION_KEYS.IMPORT_CREATED);
Expand Down
10 changes: 9 additions & 1 deletion apps/web/hooks/useOnboardUserProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useOnboardUserProjectForm() {
[API_KEYS.ONBOARD_USER],
(apiData) => commonApi(API_KEYS.ONBOARD_USER as any, { body: { ...apiData, onboarding: true } }),
{
onSuccess: () => {
onSuccess: (_, onboardData) => {
if (profileInfo) {
setProfileInfo({
...profileInfo,
Expand All @@ -33,6 +33,14 @@ export function useOnboardUserProjectForm() {
duringOnboard: true,
},
});
track({
name: 'ONBOARD',
properties: {
companySize: onboardData.companySize,
role: onboardData.role,
source: onboardData.source,
},
});
push('/');
},
}
Expand Down
7 changes: 7 additions & 0 deletions apps/web/hooks/useValidator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMutation, useQuery } from '@tanstack/react-query';

import { notify } from '@libs/notify';
import { commonApi } from '@libs/api';
import { track } from '@libs/amplitude';
import { API_KEYS, MODAL_KEYS, MODAL_TITLES } from '@config';
import { ICustomization, IErrorObject, IValidator } from '@impler/shared';
import { CodeOutput } from '@components/imports/validator/CodeOutput';
Expand Down Expand Up @@ -87,6 +88,12 @@ export function useValidator({ templateId }: UseSchemaProps) {
} else {
notify('VALIDATIONS_UPDATED');
}
track({
name: 'SAVE VALIDATION',
properties: {
isValid: !!output?.passed,
},
});
},
onError(error) {
notify('VALIDATIONS_UPDATED', { title: 'Something went wrong!', message: error?.message, color: 'red' });
Expand Down
34 changes: 33 additions & 1 deletion apps/web/libs/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ type TrackData =
}
| {
name: 'IMPORT CREATE';
properties: Record<string, never>;
properties: {
framework: string;
};
}
| {
name: 'OUTPUT FORMAT UPDATED';
Expand All @@ -65,6 +67,14 @@ type TrackData =
duringOnboard: boolean;
};
}
| {
name: 'ONBOARD';
properties: {
companySize: string;
role: string;
source: string;
};
}
| {
name: 'PROJECT SWITCH';
properties: Record<string, never>;
Expand Down Expand Up @@ -151,6 +161,28 @@ type TrackData =
properties: {
yearly: boolean;
};
}
| {
name: 'SAVE VALIDATION';
properties: {
isValid: boolean;
};
}
| {
name: 'INTEGRATE';
properties: Record<string, never>;
}
| {
name: 'CHANGE INTEGRATION FRAMEWORK';
properties: {
framework: string;
};
}
| {
name: 'CHANGE INTEGRATION STEPS';
properties: {
step: string;
};
};

export function track({ name, properties }: TrackData) {
Expand Down
4 changes: 4 additions & 0 deletions apps/web/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const { publicRuntimeConfig } = getConfig();
if (typeof window !== 'undefined' && publicRuntimeConfig.NEXT_PUBLIC_AMPLITUDE_ID) {
init(publicRuntimeConfig.NEXT_PUBLIC_AMPLITUDE_ID, {
defaultTracking: {
sessions: false,
pageViews: false,
attribution: false,
fileDownloads: false,
formInteractions: false,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/imports/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default function ImportDetails({}) {
>
Import
</Button>
<Button leftIcon={<IntegrationIcon />} id="import" onClick={onIntegrationClick}>
<Button leftIcon={<IntegrationIcon />} id="integration" onClick={onIntegrationClick}>
Integrate
</Button>
<Button variant="outline" color="red" onClick={onDeleteClick}>
Expand Down
Loading
Loading