diff --git a/tests/e2e/07-conversion-funnel.spec.ts b/tests/e2e/07-conversion-funnel.spec.ts index 03bd950..dcd6e3f 100644 --- a/tests/e2e/07-conversion-funnel.spec.ts +++ b/tests/e2e/07-conversion-funnel.spec.ts @@ -147,11 +147,6 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => { await page.screenshot({ path: 'test-results/funnel-03-stake-desktop.png' }); - // ── Step 5: Verify analytics events fired on landing page ── - // The CTA click on the landing page should have fired a cta_click event. - // Note: analytics events from the landing page may not persist across - // full-page navigation to the web-app, so we verify the integration is - // wired up by checking the landing page before navigation. console.log('[FUNNEL] ✅ Desktop funnel navigation complete'); } finally { await context.close(); @@ -229,30 +224,30 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => { } }); - test('analytics events fire at each funnel stage', async ({ browser }) => { - // Create a wallet context so we can test the full funnel including wallet-gated events + test('analytics infrastructure: collector available in landing and web-app contexts', async ({ browser }) => { + // Verifies that the addInitScript mock collector is active in both apps and that + // the umami tracker object is present. Note: this test confirms the collector + // infrastructure (addInitScript wiring, umami availability) — not that the app + // source code calls trackCtaClick on a real CTA click, since full-page navigation + // unloads the page context before events can be read. const context = await createWalletContext(browser, { privateKey: ACCOUNT_PRIVATE_KEY, rpcUrl: STACK_RPC_URL, }); - // Inject analytics collector into the wallet context await context.addInitScript({ content: analyticsCollectorScript() }); const page = await context.newPage(); page.on('console', msg => console.log(`[BROWSER] ${msg.type()}: ${msg.text()}`)); try { - // ── Landing page: verify cta_click event wiring ── + // ── Landing page: verify addInitScript collector is active ── console.log('[ANALYTICS] Loading landing page...'); await page.goto(`${STACK_WEBAPP_URL}/`, { waitUntil: 'domcontentloaded' }); const heroCta = page.locator('.header-cta button, .header-cta .k-button').first(); await expect(heroCta).toBeVisible({ timeout: 30_000 }); - // Verify the analytics module is wired by calling trackCtaClick directly. - // Clicking the real CTA triggers window.location.href which starts navigation - // and unloads the page context before we can read events. Instead, invoke - // the track function directly to verify the plumbing. + // Confirm the collector mock is live by recording a synthetic event and reading it back. await page.evaluate(() => { (window as unknown as { umami: { track: (n: string, d: Record) => void } }) .umami.track('cta_click', { label: 'hero_get_krk' }); @@ -263,38 +258,17 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => { const ctaEvent = landingEvents.find(e => e.name === 'cta_click'); expect(ctaEvent).toBeTruthy(); expect(ctaEvent!.data.label).toBe('hero_get_krk'); - console.log('[ANALYTICS] ✅ cta_click event verified with correct label'); + console.log('[ANALYTICS] ✅ Collector active on landing page'); - // ── Web-app: verify analytics integration ── + // ── Web-app: verify umami tracker is available ── await page.goto(`${STACK_WEBAPP_URL}/app/get-krk`, { waitUntil: 'domcontentloaded' }); await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 15_000 }); - // Verify analytics tracker is available in web-app context const hasUmami = await page.evaluate(() => typeof (window as unknown as { umami?: unknown }).umami !== 'undefined'); expect(hasUmami).toBeTruthy(); - console.log('[ANALYTICS] ✅ Analytics tracker available in web-app context'); + console.log('[ANALYTICS] ✅ umami tracker available in web-app context'); - // Wait for wallet_connect event to appear in analytics — the injected provider - // fires this when the wallet auto-connects. Poll the events array rather than - // sleeping: this resolves as soon as the event fires, or times out gracefully. - await page.waitForFunction( - () => ((window as unknown as { __analytics_events?: Array<{ name: string }> }).__analytics_events ?? []) - .some(e => e.name === 'wallet_connect'), - { timeout: 10_000 }, - ).catch(() => { /* wallet may not auto-connect on this page — see check below */ }); - - const webAppEvents = await getAnalyticsEvents(page); - console.log(`[ANALYTICS] Web-app events: ${JSON.stringify(webAppEvents)}`); - - // wallet_connect fires when the wallet address is set - const walletEvent = webAppEvents.find(e => e.name === 'wallet_connect'); - if (walletEvent) { - console.log('[ANALYTICS] ✅ wallet_connect event verified'); - } else { - console.log('[ANALYTICS] wallet_connect not fired (wallet did not auto-connect on this page)'); - } - - console.log('[ANALYTICS] ✅ Analytics funnel verification complete'); + console.log('[ANALYTICS] ✅ Analytics infrastructure verified'); } finally { await context.close(); }