Making Fathom Analytics Work with wire:navigate in Livewire

December 19th, 2024 • 1 minute read time

If you're using wire:navigate in Livewire, chances are Fathom Analytics won't pick up these events.

The solution for this is to listen for the livewire:navigated event and manually track a page view. Here's the full code:

document.addEventListener('livewire:navigated', () => {
    if (window.fathom) {
        window.fathom.trackPageview()
    }
})

This can can be easily added to the <head> of your page, like this:

<head>
    <script>
        document.addEventListener('livewire:navigated', () => {
            if (window.fathom) {
                window.fathom.trackPageview()
            }
        })
    </script>

    <!-- Other stuff here -->
</head>
If you found this article helpful, you'll love our practical screencasts.
Author
Alex Garrett-Smith
Share :

Comments

No comments, yet. Be the first!