Skip to content
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: 0 additions & 1 deletion .env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ NEXT_PUBLIC_GA_ID="your_google_analytics_id_here"
NEXT_PUBLIC_APP_ENV=local
NEXT_PUBLIC_LOCAL_STORAGE_PREFIX="@DockerEmuReady_"
NEXT_PUBLIC_EMUREADY_BETA_URL="https://play.google.com/store/apps/details?id=com.producdevity.emureadyapp"
NEXT_PUBLIC_VERCEL_ANALYTICS_ENABLED=false
NEXT_PUBLIC_ENABLE_ANALYTICS=false
NEXT_PUBLIC_ENABLE_KOFI_WIDGET=false
NEXT_PUBLIC_ENABLE_SENTRY=false
Expand Down
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ NEXT_PUBLIC_APP_ENV=local
NEXT_PUBLIC_GA_ID="Google-Analytics-ID"
NEXT_PUBLIC_LOCAL_STORAGE_PREFIX="@LocalEmuReady_"
NEXT_PUBLIC_EMUREADY_BETA_URL="https://play.google.com/store/apps/details?id=com.producdevity.emureadyapp"
NEXT_PUBLIC_VERCEL_ANALYTICS_ENABLED=false
NEXT_PUBLIC_ENABLE_ANALYTICS=false
NEXT_PUBLIC_ENABLE_KOFI_WIDGET=false
NEXT_PUBLIC_ENABLE_SENTRY=false
Expand Down
1 change: 0 additions & 1 deletion .env.test.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ NEXT_PUBLIC_APP_ENV=test
NEXT_PUBLIC_GA_ID=""
NEXT_PUBLIC_LOCAL_STORAGE_PREFIX="@TestEmuReady_"
NEXT_PUBLIC_EMUREADY_BETA_URL="https://play.google.com/store/apps/details?id=com.producdevity.emureadyapp"
NEXT_PUBLIC_VERCEL_ANALYTICS_ENABLED=false
NEXT_PUBLIC_ENABLE_ANALYTICS=false
NEXT_PUBLIC_ENABLE_KOFI_WIDGET=false
NEXT_PUBLIC_ENABLE_SENTRY=false
Expand Down
2 changes: 0 additions & 2 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const contentSecurityPolicyDirectives = [
"'unsafe-eval'",
'https://www.googletagmanager.com',
'https://static.cloudflareinsights.com',
'https://va.vercel-scripts.com',
'https://*.clerk.com',
'https://*.clerk.accounts.dev',
'https://clerk.emuready.com',
Expand Down Expand Up @@ -94,7 +93,6 @@ const contentSecurityPolicyDirectives = [
'https://clerk.emuready.com',
'wss://*.clerk.accounts.dev',
'wss://clerk.emuready.com',
'https://va.vercel-scripts.com',
'https://challenges.cloudflare.com',
'https://storage.ko-fi.com',
'https://clerk-telemetry.com',
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@
"@trpc/react-query": "11.17.0",
"@trpc/server": "11.17.0",
"@types/react-syntax-highlighter": "^15.5.13",
"@vercel/analytics": "^1.5.0",
"@vercel/speed-insights": "^1.2.0",
"axios": "1.16.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
1 change: 0 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function createWebServerEnv(): { [key: string]: string } {
env.NEXT_PUBLIC_ENABLE_ANALYTICS = 'false'
env.NEXT_PUBLIC_ENABLE_KOFI_WIDGET = 'false'
env.NEXT_PUBLIC_ENABLE_SENTRY = 'false'
env.NEXT_PUBLIC_VERCEL_ANALYTICS_ENABLED = 'false'
env.NEXT_PUBLIC_DISABLE_COOKIE_BANNER = 'true'
env.PLAYWRIGHT_TEST = 'true'
return env
Expand Down
69 changes: 0 additions & 69 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ allowBuilds:
"@prisma/engines": true
"@sentry/cli": true
"@tailwindcss/oxide": true
"@vercel/speed-insights": false
esbuild: true
prisma: true
sharp: true
Expand Down
8 changes: 0 additions & 8 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import './globals.css'
import { ClerkProvider } from '@clerk/nextjs'
import { shadesOfPurple } from '@clerk/themes'
import { GoogleAnalytics } from '@next/third-parties/google'
import { Analytics } from '@vercel/analytics/next'
import { SpeedInsights } from '@vercel/speed-insights/next'
import { type Metadata, type Viewport } from 'next'
import { Inter } from 'next/font/google'
import { connection } from 'next/server'
Expand Down Expand Up @@ -55,18 +53,12 @@ export default function RootLayout(props: PropsWithChildren) {
<>
<SessionTracker />
<PageViewTracker />
<SpeedInsights />
{env.GA_ID && <GoogleAnalytics gaId={env.GA_ID} />}
</>
)}
{env.ENABLE_KOFI_WIDGET && <KofiWidget />}
</Suspense>
)}
{env.ENABLE_ANALYTICS && env.VERCEL_ANALYTICS_ENABLED && (
<Suspense fallback={null}>
<Analytics />
</Suspense>
)}
</ClerkBoundary>
</body>
</html>
Expand Down
4 changes: 2 additions & 2 deletions src/app/privacy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function PrivacyPolicyPage() {
<h1 className="text-4xl font-bold text-gray-900 dark:text-white mb-8">Privacy Policy</h1>

<p className="text-gray-600 dark:text-gray-400 mb-8">
<strong>Last updated:</strong> August 1, 2025
<strong>Last updated:</strong> June 6, 2026
</p>

<div className="space-y-8">
Expand Down Expand Up @@ -169,7 +169,7 @@ function PrivacyPolicyPage() {
<strong>Clerk:</strong> User authentication and account management
</li>
<li>
<strong>Vercel:</strong> Website hosting and analytics
<strong>Vercel:</strong> Website hosting
</li>
<li>
<strong>Supabase:</strong> Database and storage services
Expand Down
169 changes: 169 additions & 0 deletions src/components/SessionTracker.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { fireEvent, render, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import SessionTracker from './SessionTracker'

type MockUser = {
id: string
externalAccounts?: { provider?: string }[]
primaryEmailAddress?: { id: string } | null
}

const testState = vi.hoisted(() => ({
analyticsAllowed: true,
pathname: '/',
user: null as MockUser | null,
analytics: {
user: {
signedIn: vi.fn(),
},
session: {
featureDiscovered: vi.fn(),
pageView: vi.fn(),
sessionEnded: vi.fn(),
sessionStarted: vi.fn(),
},
},
}))

vi.mock('@clerk/nextjs', () => ({
useUser: () => ({ user: testState.user }),
}))

vi.mock('next/navigation', () => ({
usePathname: () => testState.pathname,
}))

vi.mock('@/hooks', () => ({
useCookieConsent: () => ({ analyticsAllowed: testState.analyticsAllowed }),
}))

vi.mock('@/lib/analytics', () => ({
default: testState.analytics,
}))

describe('SessionTracker', () => {
beforeEach(() => {
vi.clearAllMocks()
testState.analyticsAllowed = true
testState.pathname = '/'
testState.user = null
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.

it('does not track session activity when analytics are disabled', () => {
testState.analyticsAllowed = false

render(<SessionTracker />)

fireEvent.click(document.body)
window.dispatchEvent(new Event('beforeunload'))

expect(testState.analytics.session.sessionStarted).not.toHaveBeenCalled()
expect(testState.analytics.session.pageView).not.toHaveBeenCalled()
expect(testState.analytics.session.sessionEnded).not.toHaveBeenCalled()
})

it('tracks real page view and interaction counts when the session ends', async () => {
const view = render(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.session.sessionStarted).toHaveBeenCalledOnce()
expect(testState.analytics.session.pageView).toHaveBeenCalledOnce()
})
expect(testState.analytics.session.pageView).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
loadTime: expect.any(Number),
pathname: '/',
}),
)

testState.pathname = '/games'
view.rerender(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.session.pageView).toHaveBeenCalledTimes(2)
})
expect(testState.analytics.session.pageView).toHaveBeenLastCalledWith({
pathname: '/games',
userId: undefined,
})

fireEvent.click(document.body)
fireEvent.keyDown(document, { key: 'Enter' })
window.dispatchEvent(new Event('beforeunload'))

expect(testState.analytics.session.sessionEnded).toHaveBeenCalledWith(
expect.objectContaining({
duration: expect.any(Number),
interactions: 2,
pageViews: 2,
sessionId: expect.any(String),
}),
)
})

it('reports the Clerk OAuth provider without counting sign-in as a page view', async () => {
const view = render(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.session.sessionStarted).toHaveBeenCalledOnce()
})

testState.user = {
id: 'user-1',
externalAccounts: [{ provider: 'oauth_google' }],
primaryEmailAddress: null,
}
view.rerender(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.user.signedIn).toHaveBeenCalledWith({
method: 'google',
userId: 'user-1',
})
})
expect(testState.analytics.session.pageView).toHaveBeenCalledOnce()
})

it('falls back to email sign-in when the Clerk user has no OAuth provider', async () => {
const view = render(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.session.sessionStarted).toHaveBeenCalledOnce()
})

testState.user = {
id: 'user-2',
primaryEmailAddress: { id: 'email-1' },
}
view.rerender(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.user.signedIn).toHaveBeenCalledWith({
method: 'email',
userId: 'user-2',
})
})
})

it('falls back to clerk sign-in when the user has no OAuth provider or email', async () => {
const view = render(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.session.sessionStarted).toHaveBeenCalledOnce()
})

testState.user = {
id: 'user-3',
primaryEmailAddress: null,
}
view.rerender(<SessionTracker />)

await waitFor(() => {
expect(testState.analytics.user.signedIn).toHaveBeenCalledWith({
method: 'clerk',
userId: 'user-3',
})
})
})
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Loading
Loading