Add Plausible custom events + weekly insights dashboard + cron

- Custom Plausible events: Pricing Click, Chat Toggle, Chat Message Sent,
  FAQ Toggle, Speedrun Nav, Mobile Menu Toggle, Scroll Depth (25/50/75/100%)
- Weekly Insights section on launch dashboard with visitor/pageview/bounce
  rate/visit duration/top pages/top referrers + analysis cards
- data/insights.json for storing weekly analytics summaries
- scripts/check-plausible-email.py — finds latest Plausible email via IMAP
- Cron job: every Mon 09:00 PYST, reads Plausible email, writes insights,
  analyzes and implements improvements
This commit is contained in:
Oliver
2026-06-09 15:04:54 -03:00
parent b51c28758d
commit 3033fc0de2
4 changed files with 320 additions and 0 deletions
+32
View File
@@ -1692,6 +1692,7 @@
})();
function slideSpeedrun(dir) {
plausible('Speedrun Nav', { props: { direction: dir > 0 ? 'next' : 'prev' } });
const slider = document.getElementById('speedrunSlider');
if (!slider) return;
const slideWidth = slider.querySelector('.video-slide').offsetWidth + 20;
@@ -2187,12 +2188,15 @@
<script>
// ── Mobile menu ──────────────────────────────────────────
function toggleMobile() {
plausible('Mobile Menu Toggle');
const nav = document.getElementById('nav-links');
nav.classList.toggle('mobile-open');
}
// ── FAQ accordion ────────────────────────────────────────
function toggleFaq(btn) {
const q = btn.innerText.replace(/[?✦]/g, '').trim();
plausible('FAQ Toggle', { props: { question: q } });
const answer = btn.nextElementSibling;
const isOpen = answer.classList.contains('open');
// Close all
@@ -2426,6 +2430,8 @@
return;
}
plausible('Pricing Click', { props: { product: product, agent: agent, period: period } });
try {
// Use a hidden form POST so the 302 redirect opens naturally in the new tab
const form = document.createElement('form');
@@ -2473,6 +2479,7 @@
let probeTimer = null;
function chatToggle() {
plausible('Chat Toggle', { props: { action: chatOpen ? 'close' : 'open' } });
chatOpen = !chatOpen;
document.getElementById('chat-widget').classList.toggle('open', chatOpen);
document.getElementById('chat-fab').classList.toggle('open', chatOpen);
@@ -2522,6 +2529,7 @@
const btn = document.getElementById("chat-send-btn");
const msg = input.value.trim();
if (!msg || chatBusy) return;
plausible('Chat Message Sent');
chatBusy = true;
chatOpenSilent();
chatAppendMsg("user", msg);
@@ -2635,6 +2643,30 @@
}
})();
/* ── Scroll Depth Tracking ────────────────────────── */
(function () {
const thresholds = [25, 50, 75, 100];
let sent = {};
let ticking = false;
window.addEventListener('scroll', function () {
if (!ticking) {
window.requestAnimationFrame(function () {
const scrolled = window.pageYOffset + window.innerHeight;
const total = document.documentElement.scrollHeight;
const pct = Math.min(100, Math.round((scrolled / total) * 100));
thresholds.forEach(function (t) {
if (pct >= t && !sent[t]) {
sent[t] = true;
plausible('Scroll Depth', { props: { percent: t + '%' } });
}
});
ticking = false;
});
ticking = true;
}
});
})();
</script>
<div class="pricing-toast" id="pricing-toast"></div>