-
Notifications
You must be signed in to change notification settings - Fork 1
Fix(project): fix amplitude loading issue #331
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
base: develop
Are you sure you want to change the base?
Changes from all commits
0989926
b714337
0f1a810
1696bb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,14 @@ | ||
| import { analytics } from '@pinback/analytics'; | ||
| import { router } from '@routes/router'; | ||
| import { useGetAmplitudeUserProperties } from '@shared/apis/queries'; | ||
| import { useEffect } from 'react'; | ||
| import AmplitudeProvider from 'src/providers/AmplitudeProvider'; | ||
| import { RouterProvider } from 'react-router-dom'; | ||
| import './App.css'; | ||
|
|
||
| function App() { | ||
| const { data: userProperties } = useGetAmplitudeUserProperties(); | ||
|
|
||
| useEffect(() => { | ||
| if (!userProperties) return; | ||
| analytics.identify( | ||
| String(userProperties.userId), | ||
| userProperties.jobRole ? { job_role: userProperties.jobRole } : undefined | ||
| ); | ||
| }, [userProperties]); | ||
|
|
||
| return <RouterProvider router={router} />; | ||
| return ( | ||
| <AmplitudeProvider> | ||
| <RouterProvider router={router} /> | ||
| </AmplitudeProvider> | ||
| ); | ||
| } | ||
|
|
||
| export default App; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { analytics } from '@pinback/analytics'; | ||
| import { useGetAmplitudeUserProperties } from '@shared/apis/queries'; | ||
| import { useEffect, type PropsWithChildren } from 'react'; | ||
|
|
||
| const AmplitudeProvider = ({ children }: PropsWithChildren) => { | ||
| const { data: userProperties } = useGetAmplitudeUserProperties(); | ||
|
|
||
| useEffect(() => { | ||
| if (!userProperties) return; | ||
| analytics.identify( | ||
| String(userProperties.userId), | ||
| userProperties.jobRole ? { job_role: userProperties.jobRole } : undefined | ||
| ); | ||
|
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 11์์ ์์ ์์ useEffect(() => {
if (!userProperties) return;
+ if (userProperties.userId == null) return;
analytics.identify(
String(userProperties.userId),
userProperties.jobRole ? { job_role: userProperties.jobRole } : undefined
);
}, [userProperties]);๐ค Prompt for AI Agents |
||
| }, [userProperties]); | ||
|
|
||
| return <>{children}</>; | ||
| }; | ||
|
|
||
| export default AmplitudeProvider; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,6 +229,7 @@ export const useGetAmplitudeUserProperties = | |
| queryFn: getAmplitudeUserProperties, | ||
| staleTime: Infinity, | ||
| retry: false, | ||
| enabled: authStorage.hasAccessToken(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐งฉ Analysis chain๐ Script executed: #!/bin/bash
# ๋ชฉ์ : ํ ํฐ ์ ์ฅ/์ธ์
์ด๊ธฐํ ์ amplitudeUserProperties ์ฟผ๋ฆฌ ์ฌ์คํ ๊ฒฝ๋ก๊ฐ ์๋์ง ํ์ธ
rg -n -C3 --type=ts --type=tsx "setAccessToken\(|clearSession\(|useGetAmplitudeUserProperties\(|amplitudeUserProperties|invalidateQueries\("
# ๋ชฉ์ : authStorage ๊ธฐ๋ฐ enabled ํจํด์ด ๋ค๋ฅธ ๊ณณ์์๋ ๋์ผํ๊ฒ ์ฌ์ฉ๋๋์ง ํ์ธ
rg -n -C2 --type=ts --type=tsx "enabled:\s*authStorage\."Repository: Pinback-Team/pinback-client Length of output: 126 ๐ Script executed: #!/bin/bash
# Search for patterns related to token storage, session clearing, and amplitude query
# Using correct rg syntax without problematic file type declarations
echo "=== Searching for setAccessToken, clearSession, and query invalidation patterns ==="
rg -n -C3 "setAccessToken|clearSession|amplitudeUserProperties|invalidateQueries" \
--include="*.ts" --include="*.tsx"
echo ""
echo "=== Searching for enabled conditions with authStorage ==="
rg -n -C2 "enabled.*authStorage|authStorage.*enabled" \
--include="*.ts" --include="*.tsx"Repository: Pinback-Team/pinback-client Length of output: 1114 ๐ Script executed: #!/bin/bash
# Find the queries.ts file and read around line 232
echo "=== Finding queries.ts file ==="
fd -t f "queries.ts"
echo ""
echo "=== Read queries.ts to see context around line 232 ==="
if [ -f "apps/client/src/shared/apis/queries.ts" ]; then
cat -n "apps/client/src/shared/apis/queries.ts" | sed -n '200,270p'
fi
echo ""
echo "=== Search for amplitudeUserProperties and authStorage in all ts/tsx files ==="
cd apps/client/src && find . -name "*.ts" -o -name "*.tsx" | xargs grep -l "amplitudeUserProperties\|authStorage" 2>/dev/null | head -20Repository: Pinback-Team/pinback-client Length of output: 2509 ๐ Script executed: #!/bin/bash
echo "=== Read authStorage.ts to understand token storage ==="
cat -n "apps/client/src/shared/utils/authStorage.ts"
echo ""
echo "=== Search for setAccessToken in the codebase ==="
grep -rn "setAccessToken" apps/client/src --include="*.ts" --include="*.tsx" | head -30
echo ""
echo "=== Search for token invalidation or refetch patterns ==="
grep -rn "invalidateQueries\|refetch" apps/client/src --include="*.ts" --include="*.tsx" | grep -i "token\|auth\|amplitude" | head -20
echo ""
echo "=== Check GoogleCallback.tsx to see how amplitudeUserProperties is used ==="
cat -n "apps/client/src/pages/onBoarding/GoogleCallback.tsx"Repository: Pinback-Team/pinback-client Length of output: 4995 ๐ Script executed: #!/bin/bash
echo "=== Check token refresh flow in queries.ts ==="
cat -n "apps/client/src/shared/apis/queries.ts" | sed -n '80,120p'
echo ""
echo "=== Check axiosInstance.ts token setter context ==="
cat -n "apps/client/src/shared/apis/setting/axiosInstance.ts" | head -50
echo ""
echo "=== Search for other places where token is set or session changes ==="
grep -rn "setAccessToken\|clearSession" apps/client/src --include="*.ts" --include="*.tsx"
echo ""
echo "=== Check Layout.tsx for how it uses amplitudeUserProperties ==="
grep -n "amplitudeUserProperties\|useGetAmplitudeUserProperties" apps/client/src/layout/Layout.tsx -B3 -A3Repository: Pinback-Team/pinback-client Length of output: 3862 ๐ Script executed: #!/bin/bash
echo "=== Try reading Layout.tsx directly ==="
if [ -f "apps/client/src/layout/Layout.tsx" ]; then
cat -n "apps/client/src/layout/Layout.tsx"
else
echo "File not found, searching for Layout file..."
find apps/client/src -name "Layout*" -type f
fi
echo ""
echo "=== Check if query is used anywhere with explicit invalidation ==="
grep -rn "invalidateQueries.*amplitudeUserProperties\|amplitudeUserProperties.*invalidateQueries" apps/client/src
echo ""
echo "=== Check full context of token refresh in axiosInstance ==="
cat -n "apps/client/src/shared/apis/setting/axiosInstance.ts" | sed -n '50,150p'Repository: Pinback-Team/pinback-client Length of output: 5453
๐ค Prompt for AI Agents |
||
| }); | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { analytics } from './src/analytics'; | ||
| import { amplitudeProvider } from './src/providers/amplitude'; | ||
| import { consoleProvider } from './src/providers/console'; | ||
| import { amplitudeAdapter } from './src/adapters/amplitude'; | ||
| import { consoleAdapter } from './src/adapters/console'; | ||
|
|
||
| export type { AnalyticsProvider, UserProperties } from './src/types'; | ||
| export type * from './src/ampli'; | ||
|
|
@@ -13,16 +13,16 @@ interface InitAnalyticsOptions { | |
|
|
||
| export const initAnalytics = ({ apiKey, isDev }: InitAnalyticsOptions): void => { | ||
| if (isDev || !apiKey) { | ||
| analytics.setProvider(consoleProvider); | ||
| analytics.setProvider(consoleAdapter); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| amplitudeProvider.init(apiKey); | ||
| analytics.setProvider(amplitudeProvider); | ||
| amplitudeAdapter.init(apiKey); | ||
| analytics.setProvider(amplitudeAdapter); | ||
| } catch (error) { | ||
|
Comment on lines
+21
to
23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐งฉ Analysis chain๐ Script executed: #!/bin/bash
set -euo pipefail
echo "== amplitude adapter ํ์ผ ์์น ๋ฐ init ์ ์ ํ์ธ =="
fd -i 'amplitude.ts' | while read -r f; do
echo "-- $f"
rg -n -C3 'init\s*[:(]|amplitudeAdapter' "$f"
done
echo
echo "== init ํธ์ถ๋ถ ํ์ธ (await ์ฌ์ฉ ์ฌ๋ถ) =="
rg -n -C2 'amplitudeAdapter\.init\('
echo
echo "== Promise ๋ฐํ ํ์
ํํธ ๊ฒ์ =="
rg -n -C2 'init\s*:\s*\(.*\)\s*=>\s*Promise|async\s+init\s*\('Repository: Pinback-Team/pinback-client Length of output: 712 ๐ Script executed: cat packages/analytics/src/adapters/amplitude.tsRepository: Pinback-Team/pinback-client Length of output: 1311 ๐ Script executed: cat packages/analytics/src/types.tsRepository: Pinback-Team/pinback-client Length of output: 353 ๐ Script executed: rg -A 5 'function initAll|export.*initAll' packages/analytics/Repository: Pinback-Team/pinback-client Length of output: 53 ๐ Script executed: # Check if node_modules or package.json has amplitude info
rg -A 3 '"@amplitude/unified"' packages/analytics/package.jsonRepository: Pinback-Team/pinback-client Length of output: 168 ๐ Script executed: # Search for any usage of initAll in the codebase to see if it's awaited elsewhere
rg -n 'initAll' packages/Repository: Pinback-Team/pinback-client Length of output: 277 ๐ Script executed: # Check the index.ts file context more broadly to understand error handling intent
cat -n packages/analytics/index.ts | head -30Repository: Pinback-Team/pinback-client Length of output: 1150 ๐ Web query:
๐ก Result: The initAll function in Citations:
๐ Web query:
๐ก Result: The Citations:
ํ์ํ ์์ :
๐ค Prompt for AI Agents |
||
| console.error('[Analytics] Failed to initialize Amplitude, falling back to console provider', error); | ||
| analytics.setProvider(consoleProvider); | ||
| console.error('[Analytics] Failed to initialize Amplitude, falling back to console adapter', error); | ||
| analytics.setProvider(consoleAdapter); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ๊ฒฝ๋ณ์ ๋๋ฝ ์ ๋ก๊ทธ์ธ ์์ฒญ์ ๋ณด๋ด์ง ์๋๋ก ๊ฐ๋๊ฐ ํ์ํฉ๋๋ค.
Line 45์์
uri: REDIRECT_URI๋ฅผ ์ฌ์ฉํ์ง๋ง,REDIRECT_URI๋ฏธ์ค์ ์undefined๋ก ์์ฒญ์ด ์ ์ก๋ฉ๋๋ค. ๋ฐฐํฌ/ํ๊ฒฝ์ค์ ์ค์์์ ์ ๋ฉด ๋ก๊ทธ์ธ ์คํจ๋ก ์ด์ด์ง ์ ์์ด ์ฌ์ ์ฐจ๋จ์ด ํ์ํฉ๋๋ค.์์ ์ ์ diff
const GoogleCallback = () => { @@ const loginWithCode = async (code: string) => { + if (!REDIRECT_URI) { + console.error('VITE_GOOGLE_REDIRECT_URI is not configured'); + alert('๋ก๊ทธ์ธ ์ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด์ฃผ์ธ์.'); + navigate('/onboarding?step=SOCIAL_LOGIN'); + return; + } + try { const res = await apiRequest.post( '/api/v3/auth/google', { code, uri: REDIRECT_URI }, { withCredentials: true } );Also applies to: 45-47
๐ค Prompt for AI Agents