Skip to content

Commit 3b606c5

Browse files
committed
better reset
1 parent 0aa0201 commit 3b606c5

1 file changed

Lines changed: 44 additions & 7 deletions

File tree

‎lib/analytics.ts‎

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,44 @@ export function cleanupEverything(): void {
350350
}
351351

352352
/**
353-
* Nuke everything with fade animation, then navigate to landing page.
354-
* This prevents creating a "third user" by ensuring we go through the landing page cleanup.
353+
* Get the base path of the current microsite
354+
* Examples:
355+
* - /fixpanel/financial/account → /fixpanel/financial/
356+
* - /fixpanel/wellness/chat → /fixpanel/wellness/
357+
* - /fixpanel/ → /fixpanel/
358+
* - /financial/account → /financial/
359+
* - / → /
360+
*/
361+
function getMicrositeBasePath(): string {
362+
const pathname = window.location.pathname;
363+
364+
// Check if we have /fixpanel/ in the path (production)
365+
if (pathname.includes('/fixpanel/')) {
366+
const parts = pathname.split('/').filter(Boolean);
367+
// parts could be ['fixpanel'] or ['fixpanel', 'financial'] or ['fixpanel', 'financial', 'account']
368+
if (parts.length <= 1) {
369+
// We're on the homepage /fixpanel/ or /fixpanel
370+
return '/fixpanel/';
371+
} else {
372+
// We're in a microsite, return /fixpanel/microsite/
373+
return `/${parts[0]}/${parts[1]}/`;
374+
}
375+
} else {
376+
// Development mode (no /fixpanel/ prefix)
377+
const parts = pathname.split('/').filter(Boolean);
378+
if (parts.length === 0) {
379+
// We're on the homepage /
380+
return '/';
381+
} else {
382+
// We're in a microsite, return /microsite/
383+
return `/${parts[0]}/`;
384+
}
385+
}
386+
}
387+
388+
/**
389+
* Nuke everything with fade animation, then reload the current microsite.
390+
* This keeps users in their current vertical while resetting all tracking data.
355391
*/
356392
export function nukePanel(): void {
357393
// Create fade overlay element
@@ -376,17 +412,18 @@ export function nukePanel(): void {
376412
});
377413

378414
setTimeout(() => {
379-
console.log("[RESET]: NUKING EVERYTHING AND RETURNING TO LANDING PAGE");
415+
console.log("[RESET]: NUKING EVERYTHING AND RELOADING CURRENT MICROSITE");
380416

381417
setTimeout(() => {
382418
// Use the centralized cleanup function
383419
cleanupEverything();
384420

385-
// Navigate to landing page (/) which will trigger ClientLayout cleanup again for double protection
386-
// This ensures we don't create a "third user" by reloading the current microsite
421+
// Navigate to current microsite's base path
422+
// This keeps users in their vertical while starting fresh
387423
setTimeout(() => {
388-
console.log("[RESET]: 🏠 Navigating to landing page...");
389-
window.location.href = window.location.origin + (window.location.pathname.includes('fixpanel') ? '/fixpanel/' : '/');
424+
const targetPath = getMicrositeBasePath();
425+
console.log(`[RESET]: 🔄 Reloading current microsite: ${targetPath}`);
426+
window.location.href = window.location.origin + targetPath;
390427
}, 200);
391428
}, 300);
392429
}, 500);

0 commit comments

Comments
 (0)