Page MenuHomePhabricator

Add analytics capabilities to Codex docs page
Closed, ResolvedPublic

Description

Goal

Using Wikimedia's analytics instance to get better data points for understanding Codex website's information architecture issues and general user behaviour for further optimizations.

Technical notes

Here's the old tracking code:

var _paq=window._paq||[];function embedTrackingCode(){var e="https://piwik.wikimedia.org/",a=document,i=a.createElement("script"),a=a.getElementsByTagName("head")[0];_paq.push(["setTrackerUrl",e+"piwik.php"]),_paq.push(["setSiteId","NN"]),i.src=e+"piwik.js",i.async=!0,i.defer=!0,a.appendChild(i)}_paq.push(["setDomains",["*.design.wikimedia.org."]]),_paq.push(["trackPageView"]),_paq.push(["enableLinkTracking"]),window.addEventListener?window.addEventListener("load",embedTrackingCode,!1):embedTrackingCode();
//# sourceMappingURL=matomo-tracking.min.js.map.json

Acceptance criteria for done

  • Continue to use Wikimedia's analytics instance (Design Style Guide has already used this)
  • Integrate in Codex VitePress docs

Event Timeline

Catrope moved this task from Backlog to In Progress on the Codex board.
Catrope removed a project: Design-System-Team.
Catrope added a subscriber: Jdrewniak.

@Jdrewniak has set up a container for this on https://piwik.wikimedia.org/ , we just need to inject a script into the docs site to feed data into that.

Change #1178088 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] docs: Add support for Matomo pageview analytics

https://gerrit.wikimedia.org/r/1178088

Change #1178089 had a related patch set uploaded (by Catrope; author: Catrope):

[integration/config@master] jjb: Set CODEX_MATOMO_URL for Codex doc builds

https://gerrit.wikimedia.org/r/1178089

Change #1178089 merged by jenkins-bot:

[integration/config@master] jjb: Set CODEX_MATOMO_URL for Codex doc builds

https://gerrit.wikimedia.org/r/1178089

I've brought up to @Jdrewniak the idea about working with the already used by Design team Matomo instance, which would streamline the setup needed. Successfully and with some outside help that's a reality now ✨

Which brings me to another point, I don't think we need to shoot with the whole Matomo Tag Manager script on our clients for a number of reasons. Comparison of the two:

Matomo Tracking scriptMatomo Tag Manager
- A small JS snippet (_paq.push([...])) you place on pages.- A single container snippet (_mtm.push({...})) you place once.
- Sends pageviews, events, ecommerce hits directly to your Matomo server.- Inside the container you configure tags (e.g., Matomo Analytics tag, Meta/GA pixels, custom HTML), triggers (when they fire), and variables (data to use).
- Changes usually require code edits/deploys.- Lets you add/edit/remove tags from a web UI with versioning, preview, and publish—no code deploys.

In the DSG we've limited the data gathered to an anonymized minimum and there is also no urgency to have versioning or A/B/C testing here to my knowledge. Let alone the performance differences of the two scripts in comparison.
For straightforward pageviews/referrals, with minimal JS we only need the tracking script.

The reason I used the tag manager is because that's what Matomo recommends for SPAs. On the docs site, the user can go to different documentation pages without actually reloading the page, because VitePress's JS just updates the page content and the URL. So for that reason I don't think these are "straightforward pageviews/referrals", because we also need Matomo to listen to hashchange. We could use the tracking script for this, but we'd have to write a hashchange event listener with a bunch of code. See this documentation which explains how this can be achieved using the tracking script, but recommends using the tag manager.

Change #1178088 merged by jenkins-bot:

[design/codex@main] docs: Add support for Matomo pageview analytics

https://gerrit.wikimedia.org/r/1178088

Change #1180240 had a related patch set uploaded (by Catrope; author: Catrope):

[operations/puppet@production] doc.wikimedia.org CSP: Allow sendBeacon for piwik

https://gerrit.wikimedia.org/r/1180240

Change #1180240 merged by RLazarus:

[operations/puppet@production] doc.wikimedia.org CSP: Allow sendBeacon for piwik (Matomo)

https://gerrit.wikimedia.org/r/1180240

Change #1180982 had a related patch set uploaded (by LorenMora; author: LorenMora):

[mediawiki/core@master] Update Codex from v2.2.1 to v2.3.1

https://gerrit.wikimedia.org/r/1180982

Test wiki created on Patch demo by LMora-WMF using patch(es) linked to this task:
https://590db65713.catalyst.wmcloud.org/w/

Change #1180982 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v2.2.1 to v2.3.1

https://gerrit.wikimedia.org/r/1180982

Test wiki on Patch demo by LMora-WMF using patch(es) linked to this task was deleted:

https://590db65713.catalyst.wmcloud.org/w/