Skip to content
Open
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
39 changes: 39 additions & 0 deletions hooks/useSprig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,43 @@ export const useSprig = () => {
router.events.on('routeChangeComplete', handleRouteChange);
return () => router.events.off('routeChangeComplete', handleRouteChange);
}, [router, sprigEnvironmentId]);

// Track feature flags page visits
useEffect(() => {
if (!sprigEnvironmentId || typeof window === 'undefined') return;

const trackFeatureFlagView = () => {
const now = Date.now();

// Prevent duplicate events within debounce period
if (now - lastEventTime < EVENT_DEBOUNCE_MS) {
return;
}

if (!window.Sprig) {
return;
}

try {
lastEventTime = now;
window.Sprig('track', 'viewed_featureflags_docs');
} catch (error) {
console.error('Sprig track failed:', error);
}
};

const handleRouteChange = (url: string) => {
if (url.includes('/docs/featureflags')) {
trackFeatureFlagView();
}
};

// Track if already on feature flags page
if (router.asPath.includes('/docs/featureflags')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this could be merged with track experiment page view above

trackFeatureFlagView();
}

router.events.on('routeChangeComplete', handleRouteChange);
return () => router.events.off('routeChangeComplete', handleRouteChange);
}, [router, sprigEnvironmentId]);
};