mirror of https://github.com/luizdepra/hugo-coder.git

Yash Mehrotra
11.28.2020 93fb14e953a1c0275635093f6d22268236b3f216
Add support for Fathom Analytics (#264)

* Add support for Fathom Analytics

* Add myself to CONTRIBUTORS.md

* Set default for serverURL and check for siteID

* Update layouts/_default/baseof.html

Co-Authored-By: Luiz F. A. de Prá <luizdepra@users.noreply.github.com>

Co-authored-by: Luiz F. A. de Prá <luizdepra@users.noreply.github.com>
1 files added
3 files modified
24 ■■■■■ changed files
CONTRIBUTORS.md 1 ●●●● patch | view | raw | blame | history
exampleSite/config.toml 6 ●●●●● patch | view | raw | blame | history
layouts/_default/baseof.html 4 ●●●● patch | view | raw | blame | history
layouts/partials/analytics/fathom.html 13 ●●●●● patch | view | raw | blame | history
CONTRIBUTORS.md
@@ -56,3 +56,4 @@
- [Anson VanDoren](https://github.com/anson-vandoren)
- [Michael Lynch](https://github.com/mtlynch)
- [FIGBERT](https://figbert.com/)
- [Yash Mehrotra](https://yashmehrotra.com)
exampleSite/config.toml
@@ -50,6 +50,12 @@
    # Custom JS
    custom_js = []
# If you want to use fathom(https://usefathom.com) for analytics, add this section
[params.fathomAnalytics]
    siteID = "ABCDE"
    # Default value is cdn.usefathom.com, overwrite this if you are self-hosting
    serverURL = "analytics.example.com"
[taxonomies]
  category = "categories"
  series = "series"
layouts/_default/baseof.html
@@ -108,6 +108,10 @@
    {{ template "_internal/google_analytics.html" . }}
    {{ if and .Site.Params.fathomAnalytics .Site.Params.fathomAnalytics.siteID }}
      {{- partial "analytics/fathom" . -}}
    {{ end }}
  </body>
</html>
layouts/partials/analytics/fathom.html
New file
@@ -0,0 +1,13 @@
<script>
(function(f, a, t, h, o, m){
    a[h]=a[h]||function(){
        (a[h].q=a[h].q||[]).push(arguments)
    };
    o=f.createElement('script'),
    m=f.getElementsByTagName('script')[0];
    o.async=1; o.src=t; o.id='fathom-script';
    m.parentNode.insertBefore(o,m)
})(document, window, '//{{ .Site.Params.fathomAnalytics.serverURL | default "cdn.usefathom.com" }}/tracker.js', 'fathom');
fathom('set', 'siteId', '{{ .Site.Params.fathomAnalytics.siteID }}');
fathom('trackPageview');
</script>