Skip to content

Commit 721b914

Browse files
committed
docs: migrate analytics from Plausible to Rybbit
1 parent e4d426b commit 721b914

6 files changed

Lines changed: 88 additions & 90 deletions

File tree

documentation/.vuepress/components/needle-button.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ function get_next_url() {
4949
<a
5050
:href="get_next_url()"
5151
:target="same_tab ? '_self' : '_blank'"
52-
class="no-external-link-icon"
53-
:class="event_goal ? ('plausible-event-name=' + event_goal + (event_position ? (' plausible-event-position=' + event_position) : '')) : ''"
52+
class="no-external-link-icon"
53+
:data-rybbit-event="event_goal || undefined"
54+
:data-rybbit-prop-position="(event_goal && event_position) ? event_position : undefined"
5455
>
55-
<button :class="event_goal ? ('plausible-event-name=' + event_goal + (event_position ? (' plausible-event-position=' + event_position) : '')) : ''">
56+
<button :data-rybbit-event="event_goal || undefined" :data-rybbit-prop-position="(event_goal && event_position) ? event_position : undefined">
5657
<slot></slot>
5758
<p v-if="false">{{ get_next_url() }}</p>
5859
</button>

documentation/.vuepress/components/stackblitz.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export default {
139139
140140
<template>
141141
<div>
142-
<button @click="openProject" class="plausible-event-name=Click+Create+Stackblitz+Project">
142+
<button @click="openProject" data-rybbit-event="Click Create Stackblitz Project">
143143
Open in StackBlitz
144144
</button>
145145
<div class="code">

documentation/.vuepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ export default defineUserConfig({
469469

470470
// stackblitz
471471
['script', { src: 'https://unpkg.com/@stackblitz/sdk/bundles/sdk.umd.js' }],
472-
['script', { src: 'https://analytics.needle.tools/js/script.tagged-events.outbound-links.js', defer: "", "data-domain": "docs.needle.tools" }]
472+
['script', { src: 'https://analytics-2.needle.tools/api/script.js', defer: "", "data-site-id": "28921995b35b" }]
473473

474474
],
475475
markdown: {

tools/api-plugins/plausible/index.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

tools/api-plugins/rybbit/index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { JSX, ParameterType } from "typedoc";
2+
3+
const optionSiteId = "rybbitSiteId";
4+
const optionScriptSrc = "rybbitScriptSrc";
5+
6+
/**
7+
* @param {import("typedoc").Application} app
8+
*/
9+
export function load(app) {
10+
11+
// Rybbit Analytics support.
12+
// Replaces the previous Plausible plugin. Rybbit auto-tracks pageviews
13+
// (so "which page was viewed" is captured out of the box). Sites are
14+
// identified by data-site-id, not by domain.
15+
16+
app.options.addDeclaration({
17+
name: optionSiteId,
18+
type: ParameterType.String,
19+
help: `Rybbit Analytics site id (data-site-id). Leave empty to disable.`,
20+
});
21+
app.options.addDeclaration({
22+
name: optionScriptSrc,
23+
type: ParameterType.String,
24+
help: `URL of the Rybbit Analytics tracking script.`,
25+
defaultValue: "https://analytics-2.needle.tools/api/script.js",
26+
});
27+
28+
app.renderer.hooks.on("head.end", (ctx) => {
29+
30+
const siteId = ctx.options.getValue(optionSiteId);
31+
if (typeof siteId !== "string") {
32+
throw TypeError(
33+
`Unexpected ${optionSiteId} type: ${JSON.stringify(siteId)}`,
34+
);
35+
}
36+
if (siteId === "") {
37+
// No site specified -> disable analytics.
38+
return JSX.createElement(JSX.Fragment, {});
39+
}
40+
const scriptSrc = ctx.options.getValue(optionScriptSrc);
41+
42+
return [
43+
JSX.createElement("script", {
44+
defer: true,
45+
src: scriptSrc,
46+
"data-site-id": siteId,
47+
}),
48+
// Rybbit auto-tracks the pageview for the current path, which already
49+
// tells us which API page was viewed. In addition we fire a custom
50+
// event carrying the page (normalized, without the version segment)
51+
// and the engine version, so we keep a per-version breakdown.
52+
JSX.createElement("script", null, JSX.createElement(JSX.Raw, {
53+
html: `
54+
// The API docs URL has this form:
55+
// /docs/api/@needle-tools/engine/3.48.3/<actually interesting part>
56+
// so we extract the interesting part and the version.
57+
window.addEventListener("load", function () {
58+
try {
59+
if (!window.rybbit || typeof window.rybbit.event !== "function") return;
60+
const parts = window.location.pathname.split("/");
61+
// find index of the part that looks like a version (contains two dots and the first two parts are numbers)
62+
const versionIndex = parts.findIndex((part) => {
63+
const subParts = part.split(".");
64+
return subParts.length === 3 && !isNaN(subParts[0]) && !isNaN(subParts[1]);
65+
});
66+
if (versionIndex === -1) return;
67+
let page = parts.slice(versionIndex + 1).join("/");
68+
if (page.startsWith("/")) page = page.slice(1);
69+
const version = parts[versionIndex];
70+
console.debug("Rybbit api-pageview", { page, version });
71+
window.rybbit.event("api-pageview", { page: page || "index", version });
72+
} catch (e) {
73+
console.debug("Rybbit api-pageview error", e);
74+
}
75+
});
76+
`
77+
})),
78+
];
79+
});
80+
}

tools/build_api_docs.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ async function produceDocs(packageDir, outputDirectory, hostedBaseUrl) {
318318
"typedoc-plugin-extras",
319319
"./tools/api-plugins/index.js",
320320
"./tools/api-plugins/keywords/index.js",
321-
"./tools/api-plugins/plausible/index.js",
321+
"./tools/api-plugins/rybbit/index.js",
322322
"./tools/api-plugins/component-lookup/index.js",
323323
"./tools/api-plugins/meta-description/index.js",
324324
"./tools/api-plugins/canonical-url/index.js",
@@ -336,8 +336,7 @@ async function produceDocs(packageDir, outputDirectory, hostedBaseUrl) {
336336
useFirstParagraphOfCommentAsSummary: true,
337337

338338
// analytics
339-
plausibleSiteDomain: "api.needle.tools",
340-
plausibleSiteOrigin: "analytics.needle.tools/js/",
339+
rybbitSiteId: "aa45202539de",
341340
});
342341

343342
// inline sources plugin

0 commit comments

Comments
 (0)