From 2650b0a3dfe13c7c5d4f877c13b721a4bac9a42c Mon Sep 17 00:00:00 2001 From: Vercel Date: Sun, 22 Mar 2026 12:56:10 +0000 Subject: [PATCH] Install Vercel Web Analytics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Vercel Web Analytics Configuration ## Summary Improved the existing Vercel Web Analytics configuration in this Phaser/Vite project to follow the latest best practices from the official Vercel documentation. ## What Was Already Present The project already had: - `@vercel/analytics` package installed (version ^2.0.1) - Basic `inject()` call in `src/main.ts` ## Changes Made ### Modified Files - **src/main.ts**: Enhanced the `inject()` call to include proper environment detection ### Configuration Improvements According to the latest Vercel Analytics documentation, the `inject()` function should include a `mode` parameter to properly handle development vs production environments. **Before:** ```typescript inject(); ``` **After:** ```typescript inject({ mode: (import.meta as any).env?.DEV ? 'development' : 'production', }); ``` This improvement ensures: 1. Analytics operates in the correct mode for each environment 2. Development events are properly tagged/handled differently from production 3. The configuration follows the recommended best practices from Vercel's documentation ## Implementation Details The configuration leverages Vite's environment detection (`import.meta.env.DEV`) to automatically set: - `'development'` mode when running `npm run dev` - `'production'` mode when building for production with `npm run build` This is the recommended approach for vanilla JavaScript/TypeScript projects (non-React frameworks) as documented at https://vercel.com/docs/analytics/package. ## Verification - ✅ TypeScript compilation successful - ✅ Build completed successfully (1,529.70 kB production bundle) - ✅ No breaking changes to existing functionality - ✅ Package already installed, dependencies up to date ## Notes - The `inject()` function is the correct approach for this Phaser game (vanilla TypeScript) - React/Next.js projects would use the `` component instead - The analytics will start tracking once deployed to Vercel with Web Analytics enabled in the dashboard Co-authored-by: Vercel --- src/main.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 9411edc..423d374 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,7 +10,9 @@ import { inject } from '@vercel/analytics'; const game = new Phaser.Game(createGameConfig([BootScene, MenuScene, GameScene, GameOverScene])); // Initialize Vercel Web Analytics -inject(); +inject({ + mode: (import.meta as any).env?.DEV ? 'development' : 'production', +}); // Expose game instance for debugging in development only if ((import.meta as any).env?.DEV) {