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

Hotfix: User Property 필드 수정 #1686

Merged
merged 3 commits into from
Nov 11, 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
35 changes: 35 additions & 0 deletions src/api/endpoint/members/getMemberProperty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useQuery } from '@tanstack/react-query';
import { z } from 'zod';

import { createEndpoint } from '@/api/typedAxios';

export const getMemberproperty = createEndpoint({
request: {
method: 'GET',
url: 'api/v1/members/property',
},
serverResponseScheme: z.object({
id: z.number(),
major: z.string(),
job: z.string(),
organization: z.string(),
part: z.array(z.string()),
generation: z.array(z.number()),
coffeeChatStatus: z.string(),
receivedCoffeeChatCount: z.number(),
sentCoffeeChatCount: z.number(),
}),
});

/**
* @desc Amplitude User Properties
*/
export const useGetMemberProperty = () => {
return useQuery({
queryKey: ['getMemberProperty'],
queryFn: async () => {
const data = await getMemberproperty.request();
return data;
},
});
};
7 changes: 4 additions & 3 deletions src/components/eventLogger/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ type CommunityFeedData = {
images: string[];
};


export type UserProperties = {
id: number;
major: string;
university: string;
organization: string;
job: string;
company: string;
part: string[];
generation: number[];
coffeeChatStatus: string;
receivedCoffeeChatCount: number;
sentCoffeeChatCount: number;
};

type GotoCoffeechat = {
Expand Down
27 changes: 14 additions & 13 deletions src/components/eventLogger/providers/AmplitudeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC, ReactNode, useEffect, useState } from 'react';

import { useGetMemberOfMe } from '@/api/endpoint/members/getMemberOfMe';
import { getMemberProfileOfMe } from '@/api/endpoint_LEGACY/members';
import { useGetMemberProperty } from '@/api/endpoint/members/\bgetMemberProperty';
import { EventLoggerContext } from '@/components/eventLogger/context';
import { createConsoleLogController } from '@/components/eventLogger/controllers/consoleLog';

Expand All @@ -13,6 +13,7 @@ interface EventLoggerProviderProps {
const AmplitudeProvider: FC<EventLoggerProviderProps> = ({ children, apiKey }) => {
const [controller, setController] = useState(createConsoleLogController());
const { data } = useGetMemberOfMe();
const { data: property } = useGetMemberProperty();

useEffect(() => {
if (!apiKey) {
Expand All @@ -21,21 +22,21 @@ const AmplitudeProvider: FC<EventLoggerProviderProps> = ({ children, apiKey }) =
}
const initializeAmplitude = async () => {
try {
const profile = await getMemberProfileOfMe();
const { createAmplitudeController } = await import('@/components/eventLogger/controllers/amplitude');

const amplitudeController = createAmplitudeController(apiKey, data?.id ? `${data.id}` : undefined);

// user_properties 설정
if (data && profile) {
// user_properties 주입
if (data && property) {
amplitudeController.setUserProperties({
id: data.id,
major: profile.major,
university: profile.university,
job: profile.careers.length > 0 ? profile.careers[0].title : '',
company: profile.careers.length > 0 ? profile.careers[0].companyName : '',
generation: profile.soptActivities.map((activity) => activity.generation),
part: [...new Set(profile.soptActivities.map((activity) => activity.part))],
id: property.id,
job: property.job,
major: property.major,
organization: property.organization,
generation: property.generation,
part: property.part,
coffeeChatStatus: property.coffeeChatStatus,
receivedCoffeeChatCount: property.receivedCoffeeChatCount,
sentCoffeeChatCount: property.sentCoffeeChatCount,
});
}

Expand All @@ -46,7 +47,7 @@ const AmplitudeProvider: FC<EventLoggerProviderProps> = ({ children, apiKey }) =
};

initializeAmplitude();
}, [apiKey, data]);
}, [apiKey, data, property]);

return <EventLoggerContext.Provider value={controller}>{children}</EventLoggerContext.Provider>;
};
Expand Down
Loading