fix: address review feedback on analytics test clarity and dead code
- Rename analytics test to accurately describe what it verifies (collector infrastructure wiring, not app-level event firing) - Add comment explaining why real CTA click cannot be used (full-page navigation unloads context before events can be read) - Remove wallet_connect if/else block that had no assertion - Remove dead Step 5 comment block with no assertions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4465869788
commit
2611280c8f
1 changed files with 12 additions and 38 deletions
|
|
@ -147,11 +147,6 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
|
||||||
|
|
||||||
await page.screenshot({ path: 'test-results/funnel-03-stake-desktop.png' });
|
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');
|
console.log('[FUNNEL] ✅ Desktop funnel navigation complete');
|
||||||
} finally {
|
} finally {
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
@ -229,30 +224,30 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('analytics events fire at each funnel stage', async ({ browser }) => {
|
test('analytics infrastructure: collector available in landing and web-app contexts', async ({ browser }) => {
|
||||||
// Create a wallet context so we can test the full funnel including wallet-gated events
|
// 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, {
|
const context = await createWalletContext(browser, {
|
||||||
privateKey: ACCOUNT_PRIVATE_KEY,
|
privateKey: ACCOUNT_PRIVATE_KEY,
|
||||||
rpcUrl: STACK_RPC_URL,
|
rpcUrl: STACK_RPC_URL,
|
||||||
});
|
});
|
||||||
// Inject analytics collector into the wallet context
|
|
||||||
await context.addInitScript({ content: analyticsCollectorScript() });
|
await context.addInitScript({ content: analyticsCollectorScript() });
|
||||||
|
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
page.on('console', msg => console.log(`[BROWSER] ${msg.type()}: ${msg.text()}`));
|
page.on('console', msg => console.log(`[BROWSER] ${msg.type()}: ${msg.text()}`));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ── Landing page: verify cta_click event wiring ──
|
// ── Landing page: verify addInitScript collector is active ──
|
||||||
console.log('[ANALYTICS] Loading landing page...');
|
console.log('[ANALYTICS] Loading landing page...');
|
||||||
await page.goto(`${STACK_WEBAPP_URL}/`, { waitUntil: 'domcontentloaded' });
|
await page.goto(`${STACK_WEBAPP_URL}/`, { waitUntil: 'domcontentloaded' });
|
||||||
|
|
||||||
const heroCta = page.locator('.header-cta button, .header-cta .k-button').first();
|
const heroCta = page.locator('.header-cta button, .header-cta .k-button').first();
|
||||||
await expect(heroCta).toBeVisible({ timeout: 30_000 });
|
await expect(heroCta).toBeVisible({ timeout: 30_000 });
|
||||||
|
|
||||||
// Verify the analytics module is wired by calling trackCtaClick directly.
|
// Confirm the collector mock is live by recording a synthetic event and reading it back.
|
||||||
// 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.
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
(window as unknown as { umami: { track: (n: string, d: Record<string, unknown>) => void } })
|
(window as unknown as { umami: { track: (n: string, d: Record<string, unknown>) => void } })
|
||||||
.umami.track('cta_click', { label: 'hero_get_krk' });
|
.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');
|
const ctaEvent = landingEvents.find(e => e.name === 'cta_click');
|
||||||
expect(ctaEvent).toBeTruthy();
|
expect(ctaEvent).toBeTruthy();
|
||||||
expect(ctaEvent!.data.label).toBe('hero_get_krk');
|
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 page.goto(`${STACK_WEBAPP_URL}/app/get-krk`, { waitUntil: 'domcontentloaded' });
|
||||||
await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 15_000 });
|
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');
|
const hasUmami = await page.evaluate(() => typeof (window as unknown as { umami?: unknown }).umami !== 'undefined');
|
||||||
expect(hasUmami).toBeTruthy();
|
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
|
console.log('[ANALYTICS] ✅ Analytics infrastructure verified');
|
||||||
// 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');
|
|
||||||
} finally {
|
} finally {
|
||||||
await context.close();
|
await context.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue