Skip to content
Open
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
37 changes: 37 additions & 0 deletions src/components/posthog.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@
debug: location.hostname === 'localhost' || location.hostname === '127.0.0.1'
})

// Track homepage section views (50%+ visible, once per section per page load).
if (location.pathname === '/') {
var sectionIds = ['overview', 'testimonials', 'how-promptless-works', 'capabilities'];
var viewedSections = {};
var sectionObs = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
var id = entry.target.id;
if (viewedSections[id]) return;
viewedSections[id] = true;
posthog.capture('section_viewed', { section: id, page: location.pathname });
});
}, { threshold: 0.5 });
sectionIds.forEach(function (id) {
var el = document.getElementById(id);
if (el) sectionObs.observe(el);
});
}

// Track scroll depth on blog posts (25/50/75/100%, once per milestone per page load).
if (location.pathname.indexOf('/blog/') === 0 && location.pathname !== '/blog/' && location.pathname !== '/blog/all') {
var scrollMilestones = [25, 50, 75, 100];
var firedMilestones = {};
var scrollHandler = function () {
var docHeight = document.documentElement.scrollHeight - window.innerHeight;
if (docHeight <= 0) return;
var pct = Math.round((window.scrollY / docHeight) * 100);
scrollMilestones.forEach(function (m) {
if (pct >= m && !firedMilestones[m]) {
firedMilestones[m] = true;
posthog.capture('scroll_depth', { percent: m, page: location.pathname });
}
});
};
window.addEventListener('scroll', scrollHandler, { passive: true });
}

// Unmask the Pagefind search input and track search queries.
new MutationObserver(function(_, obs) {
var input = document.querySelector('site-search input, .pagefind-ui__search-input');
Expand Down
5 changes: 5 additions & 0 deletions src/components/shared/AnnouncementBanner.astro
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const storageKey = `pl_banner_dismissed_${campaign}`;
banner.setAttribute('hidden', '');
localStorage.setItem(storageKey, '1');
root.style.removeProperty('--sl-nav-height');

var campaign = storageKey.replace('pl_banner_dismissed_', '');
if (window.posthog) {
window.posthog.capture('banner_dismissed', { campaign: campaign });
}
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/site/BlogNewsletterCTA.astro
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@

if (!res.ok) throw new Error('Submission failed');

window.posthog?.capture('blog_newsletter_subscribed', {
window.posthog?.capture('email_captured', {
intent: 'newsletter',
location: 'blog',
campaign: '',
$set: { email },
});

Expand Down
4 changes: 3 additions & 1 deletion src/components/site/BlogRequestDemo.astro
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@

try { sessionStorage.setItem('pl_demo_email', email); } catch {}

window.posthog?.capture('blog_demo_requested', {
window.posthog?.capture('email_captured', {
intent: 'demo',
location: 'blog',
campaign: '',
$set: { email },
});

Expand Down
7 changes: 7 additions & 0 deletions src/components/site/BrokenLinkReportForm.astro
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ const apiBaseUrl = (rawApiBaseUrl || fallbackApiBaseUrl).replace(/\/+$/, '');
$set: { email },
});

window.posthog?.capture('email_captured', {
intent: 'free_tool',
location: 'free_tools',
campaign: '',
$set: { email },
});

form.reset();
const anchorsToggle = form.querySelector('#broken-link-check-anchors');
if (anchorsToggle instanceof HTMLInputElement) anchorsToggle.checked = true;
Expand Down
4 changes: 3 additions & 1 deletion src/components/site/DemoBooking.astro
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@
} catch (_) {}

if (window.posthog) {
window.posthog.capture('demo_requested', {
window.posthog.capture('email_captured', {
intent: 'demo',
location: 'demo_page',
campaign: '',
$set: { email: email },
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/site/Hero.astro
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ const {
if (email) {
try { sessionStorage.setItem('pl_demo_email', email); } catch {}
}
(window as any).posthog?.capture('demo_requested', {
(window as any).posthog?.capture('email_captured', {
intent: 'demo',
location: 'hero',
campaign: '',
...(email ? { $set: { email } } : {}),
});

Expand Down
12 changes: 11 additions & 1 deletion src/components/site/pricing/GrowthBundleSelector.astro
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ const selectId = 'growth-pages';
}
};

select.addEventListener('change', update);
select.addEventListener('change', function () {
update();
var opt = select.options[select.selectedIndex];
if (opt && window.posthog) {
window.posthog.capture('pricing_bundle_changed', {
bundle_id: opt.value,
bundle_label: opt.textContent.trim(),
price_label: (opt.dataset.priceLabel || '').trim(),
});
}
});
update();
};

Expand Down
Loading