Skip to content

A new page for Site Statistics fetched from Matomo APIs#637

Merged
anenadic merged 11 commits into
mainfrom
add_stats
Jun 8, 2026
Merged

A new page for Site Statistics fetched from Matomo APIs#637
anenadic merged 11 commits into
mainfrom
add_stats

Conversation

@shraddha-bajare

@shraddha-bajare shraddha-bajare commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Fixes #588 #615

Changes proposed in this pull request:

Approach

Fetch data at build time from Matomo APIs via a python script, write it to a _data/matomo_stats.json file, then render it on a new RSQKit page - Site Statistics via Liquid templates.
Schedule the run for monthly stats.

It is consistent with how RSQKit already uses _data/ for YAML data files.

Env variables to set : MATOMO_URL, SITE_ID, TOKEN

Implementation

  • A python script - to fetch stats via matomo APIs
  • It stores data at - _data/matomo_stats.json
  • Added workflow to run 1st for every month at 6 am to fetch stats
  • Created a html for new page Site Statistics

Notes for reviewers:

  • @shoaibsufi Please review the approach and suggest if this is okay :) Also could you help me with icon image for Site Stats.
    For now I have not set TOKEN, so for testing I have fed stats default values to show. Once I get token, real stats values would start appearing on Site Statistics page.

@netlify

netlify Bot commented May 6, 2026

Copy link
Copy Markdown

Deploy Preview for everse-rsqkit-testing ready!

Name Link
🔨 Latest commit a83a57b
🔍 Latest deploy log https://app.netlify.com/projects/everse-rsqkit-testing/deploys/69fb38e4e0f77900080c2b25
😎 Deploy Preview https://deploy-preview-637--everse-rsqkit-testing.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@shraddha-bajare shraddha-bajare self-assigned this May 6, 2026
@shraddha-bajare shraddha-bajare requested a review from shoaibsufi May 6, 2026 11:11
@shraddha-bajare shraddha-bajare changed the title Page showing Site Statistics fetched from Matomo APIs A new page for Site Statistics fetched from Matomo APIs May 6, 2026
@shraddha-bajare shraddha-bajare modified the milestone: May 2026 May 6, 2026
@shraddha-bajare shraddha-bajare added enhancement New feature or request labels May 6, 2026
@shoaibsufi shoaibsufi requested a review from sparkslabs May 12, 2026 10:42
Comment thread .github/workflows/fetch-matomo-stats.yml Outdated
@netlify

netlify Bot commented May 26, 2026

Copy link
Copy Markdown

Deploy Preview for rsqkit-testing ready!

Name Link
🔨 Latest commit ce00a14
🔍 Latest deploy log https://app.netlify.com/projects/rsqkit-testing/deploys/6a157ba38161120008b794d0
😎 Deploy Preview https://deploy-preview-637--rsqkit-testing.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sparkslabs sparkslabs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend merge. :-)

Lots of little comments inline (hopefully useful - some feel a bit nit-picky). Some actionable, some to consider if you agree or not.

If you agree with them, I'd suggest a follow on PR for the minor changes, rather than block this PR, and merge this PR for this release.

Comment thread pages/site_statistics.md
title: Site Statistics
---

This page provides an overview of how the site is used and accessed. The statistics are collected using Matomo, an open-source analytics platform designed with privacy in mind.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of Matamo before this PR. As a result, I googled Matamo, and discovered that while the code is open source the hosting is a paid for platform. It took a fair amount of digging around to identify that we're using a hosted instance of Matamo. (hosted by one of the partners but hosted nonetheless)

As a result, I think an extra sentence to state that we are using a non-commercial/private instance of Matamo - rather than the commercial service - would be a good idea)

There's several reasons:

  • Clarity on "what data is going where and being processed where" . (Someone who looks will care and appreciate the detail
  • Makes it clearer that we have an extra dependency - and noting who owns it. (for when we need to maintain this)

This can be done as a follow on PR.

import requests
from datetime import date

MATOMO_URL = os.environ.get("MATOMO_URL", "https://matomo.research.software/")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment here (or somewhere) to state who "owns" https://matomo.research.software/ would be a good idea and who to contact if there's a problem would be useful. (I mistakenly assumed this was run by Matamo, not by who actually runs it)

from datetime import date

MATOMO_URL = os.environ.get("MATOMO_URL", "https://matomo.research.software/")
SITE_ID = os.environ.get("MATOMO_SITE_ID", "7")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar - about where the 7 comes from.

return data


def fetch_live():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick -
fetch_live ... what?

I'd probably call this "fetch_live_stats_from_matamo"

}


def api(method, extra=""):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General/nitpick - I tend to expect function names to be active. (Methods can be passive if they're returning data, but I still active methods to be active). something like "call_api" - or even "call_matamo_api"

(not a blocker, more an observation)

],
"referrers": [
{"type": r["label"], "visits": r["nb_visits"]}
for r in (referrers if isinstance(referrers, list) else [])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This - (referrers if isinstance(referrers, list) else [] is convoluted here. I'd personally put that above, directly below

    referrers = api(
        "Referrers.getReferrerType",
        "&period=range&date=last365"
    )

ie something more like

    referrers = call_matamo_api(
        "Referrers.getReferrerType",
        "&period=range&date=last365"
    )
   if not referrers:
      referrers = []

Similar comment for countries.

output = DUMMY_DATA

out_path = os.path.join(
os.path.dirname(__file__), "../../_data/matomo_stats.json"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment here as to why this is writing upwards in the tree would be welcome. ( I get the reason, but seeing ".." in scripts always makes me pause :-) )

- name: Install dependencies
run: pip install requests

- name: Fetch Matomo Stats

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest renaming this to include where the matamo stats are likely pulled from ("Fetch Matamo Stats from eScience Center NL's servers"). Or probably better: just putting that as a comment. (YAML allows comments after all).

@anenadic anenadic merged commit 58a20b5 into main Jun 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monthly snapshot of RSQKit page hits

4 participants