Fathom events #52
Closed
carstenjaksch
started this conversation in
Ideas
Replies: 1 comment 5 replies
|
Hey thanks for sharing. This might be helpful for others who want (and trust) their marketers to be able to add events from the CP and not in the templates. |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have added an easy way to track Fathom events. Maybe this is something for you:
{{ if seo:use_fathom }} <script src="https://cdn.usefathom.com/script.js" site="{{ seo:fathom }}" defer></script> {{ if seo:fathom_events }} <script> document.addEventListener('DOMContentLoaded', function() { if (typeof fathom !== 'undefined') { {{ seo:fathom_events }} } }); function trackEvent(name, selector, eventName = 'click', value = 0) { const element = document.querySelector(selector); element?.addEventListener(eventName, function(event) { fathom.trackEvent(name, { _value: value, }); }, { once: true }); } </script> {{ /if }} {{ /if }}Additionally, a code field is added to the CP.
This is how the end result looks like:
Only thing missing is a hint about the
trackEventfunction.All reactions