Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fathom analytics #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ If that's not enough, you can see [Overriding templates](#overriding-templates)
* Keep your regular pages in the `content` folder. To create a new page, run `hugo new page-title.md`
* Keep your blog posts in the `content/posts` folder. To create a new post, run `hugo new posts/post-title.md`

### Analytics

While using Google Analytics is implemented in Hugo by default this template also can be used with [Fathom Analytics](https://usefathom.com/).

In your `config.toml` you can specify your _siteID_ and, if you self-hosting, the tracker URL.

```yaml
[params.fathomAnalytics]
siteID = "ABCDE"
# Default value is cdn.usefathom.com, overwrite this if you are self-hosting
# serverURL = "analytics.example.com"
```

### More customizations

#### Overriding templates
Expand Down
5 changes: 5 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ enableEmoji = true # Shorthand emojis in content files - https://gohugo.io/func
# googleAnalytics = "UA-123-45"
# disqusShortname = "yourdiscussshortname"

[params.fathomAnalytics]
# siteID = "ABCDE"
# Default value is cdn.usefathom.com, overwrite this if you are self-hosting
# serverURL = "analytics.example.com"

[author]
name = "John Doe"

Expand Down
4 changes: 4 additions & 0 deletions layouts/partials/analytics.html
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{{ template "_internal/google_analytics_async.html" . }}

{{ if and .Site.Params.fathomAnalytics .Site.Params.fathomAnalytics.siteID }}
{{- partial "analytics/fathom" . -}}
{{ end }}
13 changes: 13 additions & 0 deletions layouts/partials/analytics/fathom.html
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ features = [
"featured image",
"social icons",
"google analytics",
"fathom analytics",
"disqus"
]
min_version = 0.43
Expand Down