From a19a00d74b35f0ca8f4c289c9e652a5bedc1016b Mon Sep 17 00:00:00 2001 From: Alexander Fuks Date: Sun, 25 Feb 2024 22:50:41 +0400 Subject: [PATCH] feat(analytics)!: add post pageviews for GoatCounter (#1543) --------- Co-authored-by: Cotes Chung <11371340+cotes2020@users.noreply.github.com> --- _config.yml | 15 +++++++++----- _includes/analytics/goatcounter.html | 6 ++++++ _includes/analytics/google.html | 13 ++++++++++++ _includes/goatcounter.html | 8 ------- _includes/google-analytics.html | 14 ------------- _includes/head.html | 2 +- _includes/js-selector.html | 31 ++++++++++++++++++++-------- _includes/pageviews/goatcounter.html | 18 ++++++++++++++++ _layouts/post.html | 18 ++++++++++++---- _sass/layout/post.scss | 2 +- 10 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 _includes/analytics/goatcounter.html create mode 100644 _includes/analytics/google.html delete mode 100644 _includes/goatcounter.html delete mode 100644 _includes/google-analytics.html create mode 100644 _includes/pageviews/goatcounter.html diff --git a/_config.yml b/_config.yml index 79d451fe..79f153d5 100644 --- a/_config.yml +++ b/_config.yml @@ -49,11 +49,16 @@ google_site_verification: # fill in to your verification string # ↑ -------------------------- # The end of `jekyll-seo-tag` settings -google_analytics: - id: # fill in your Google Analytics ID - -goatcounter: - id: # fill in your Goatcounter ID +# Web Analytics Settings +analytics: + google: + id: # fill in your Google Analytics ID + goatcounter: + id: # fill in your GoatCounter ID + +# Pageviews settings +pageviews: + provider: # now only supports 'goatcounter' # Prefer color scheme setting. # diff --git a/_includes/analytics/goatcounter.html b/_includes/analytics/goatcounter.html new file mode 100644 index 00000000..78c90b72 --- /dev/null +++ b/_includes/analytics/goatcounter.html @@ -0,0 +1,6 @@ + + diff --git a/_includes/analytics/google.html b/_includes/analytics/google.html new file mode 100644 index 00000000..d0aac651 --- /dev/null +++ b/_includes/analytics/google.html @@ -0,0 +1,13 @@ + + + diff --git a/_includes/goatcounter.html b/_includes/goatcounter.html deleted file mode 100644 index 4d21d21e..00000000 --- a/_includes/goatcounter.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - diff --git a/_includes/google-analytics.html b/_includes/google-analytics.html deleted file mode 100644 index e5e5119e..00000000 --- a/_includes/google-analytics.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - diff --git a/_includes/head.html b/_includes/head.html index 9bad78a7..7c093597 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -72,7 +72,7 @@ {% endif %} - {% if jekyll.environment == 'production' and site.google_analytics.id != empty and site.google_analytics.id %} + {% if jekyll.environment == 'production' and site.analytics.google.id != empty and site.analytics.google.id %} diff --git a/_includes/js-selector.html b/_includes/js-selector.html index 1a1fa580..b37d7103 100644 --- a/_includes/js-selector.html +++ b/_includes/js-selector.html @@ -95,19 +95,32 @@ {% endif %} + +{% if page.layout == 'post' %} + {% assign provider = site.pageviews.provider %} + + {% if provider and provider != empty %} + {% case provider %} + {% when 'goatcounter' %} + {% if site.analytics[provider].id != empty and site.analytics[provider].id %} + {% include pageviews/{{ provider }}.html %} + {% endif %} + {% endcase %} + {% endif %} +{% endif %} + {% if jekyll.environment == 'production' %} {% if site.pwa.enabled %} {% endif %} - - {% if site.google_analytics.id != empty and site.google_analytics.id %} - {% include google-analytics.html %} - {% endif %} - - - {% if site.goatcounter.id != empty and site.goatcounter.id %} - {% include goatcounter.html %} - {% endif %} + + {% for analytics in site.analytics %} + {% capture str %}{{ analytics }}{% endcapture %} + {% assign type = str | split: '{' | first %} + {% if site.analytics[type].id and site.analytics[type].id != empty %} + {% include analytics/{{ type }}.html %} + {% endif %} + {% endfor %} {% endif %} diff --git a/_includes/pageviews/goatcounter.html b/_includes/pageviews/goatcounter.html new file mode 100644 index 00000000..af536dbd --- /dev/null +++ b/_includes/pageviews/goatcounter.html @@ -0,0 +1,18 @@ + + diff --git a/_layouts/post.html b/_layouts/post.html index f7818bf6..f666d716 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -74,12 +74,22 @@

{{ page.title }}

- - {% include read-time.html content=content prompt=true lang=lang %} +
+ + {% if site.pageviews.provider and site.analytics[site.pageviews.provider].id %} + + + + + {{ site.data.locales[lang].post.pageview_measure }} + + {% endif %} + + + {% include read-time.html content=content prompt=true lang=lang %} +
- -
diff --git a/_sass/layout/post.scss b/_sass/layout/post.scss index efbde822..a6dc878c 100644 --- a/_sass/layout/post.scss +++ b/_sass/layout/post.scss @@ -15,7 +15,7 @@ } h1 + .post-meta { - > span + span::before { + span + span::before { @include dot; }