Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions pkgs/website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export default defineConfig({
src: PLAUSIBLE_PROXY.url + PLAUSIBLE_PROXY.scriptPath,
},
},
{
tag: 'script',
content: `window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }`,
},
{
tag: 'meta',
attrs: {
Expand Down
37 changes: 37 additions & 0 deletions pkgs/website/src/components/CodeOverlay.astro
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,22 @@
</style>

<script>
// TypeScript declaration for Plausible
declare global {
interface Window {
plausible?: (event: string, options?: { props?: Record<string, string | number> }) => void;
}
}

// Global flag to track if auto-scroll animation is running
let isAutoScrolling = false;

// Flag to track if programmatic scroll is happening (auto-scroll or scroll-to-top)
let isProgrammaticScroll = false;

// Flag to track if manual scroll event has been sent (only send once)
let hasTrackedManualScroll = false;

const handleRevealButton = () => {
const button = document.querySelector('.reveal-button') as HTMLElement | null;
const overlay = document.querySelector('.code-overlay') as HTMLElement | null;
Expand All @@ -329,6 +342,11 @@
if (!button || !overlay || !scrollableContainer || !scrollableInner) return;

button.addEventListener('click', async () => {
// Track custom event in Plausible
if (typeof window.plausible !== 'undefined') {
window.plausible('home:reveal-code');
}

const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

// Helper to animate scroll with custom duration (cancellable on user interaction)
Expand Down Expand Up @@ -445,6 +463,14 @@
return;
}

// Track manual scroll event (only once, and only if not programmatic)
if (!hasTrackedManualScroll && !isProgrammaticScroll) {
hasTrackedManualScroll = true;
if (typeof window.plausible !== 'undefined') {
window.plausible('home:code-scroll');
}
}

if (scrollableInner.scrollTop > 50) {
button.style.display = 'block';
} else {
Expand All @@ -456,7 +482,14 @@
scrollableInner.addEventListener('scroll', updateButtonVisibility);

button.addEventListener('click', () => {
// Mark as programmatic scroll to avoid tracking
isProgrammaticScroll = true;
scrollableInner.scrollTo({ top: 0, behavior: 'smooth' });

// Reset flag after scroll completes
setTimeout(() => {
isProgrammaticScroll = false;
}, 1000);
});
};

Expand All @@ -480,6 +513,10 @@
if (scrollTopButton) {
scrollTopButton.style.display = 'none';
}

// Note: hasTrackedManualScroll is NOT reset here
// This means we track manual scroll only once per page session,
// even if user reveals, resets, and reveals again
});
};

Expand Down