jfrome1 / NTW2029

https://ntw-2029.vercel.app
1 stars 1 forks source link

Add feelback and analytics #10

Closed JojokCreator closed 2 months ago

JojokCreator commented 2 months ago

To do this I created a override Footer component the same as TableofContents. It's called FeedbackAnalyticsComponent.astro

Feelback addition.

<FeelbackMessage 
contentSetId="a0d75f8f-e94b-4e67-ab72-8c595f37b914"
textAnswer="Thanks for your feedback"
withEmail
placeholder="Type your message"
/>

The script below adds umami analytics event to each nutshell click only if it's closed.

<script>
    declare global {
        interface Window {
            umami: any
        }
    }
    window.addEventListener("load", function() {
        const links = document.querySelectorAll(".nutshell-expandable") as NodeListOf<HTMLAnchorElement>;
        links.forEach(link => {
            link.addEventListener("click", function() {
            if (link.getAttribute("mode") === "open") {
            console.log("click")
            window.umami.track("openNutshell", { page: document.title, text: link.textContent });
            }
            });
        });
    });
</script>