Skip to content

Commit ef29c69

Browse files
authored
add rybbit analytics (#2197)
1 parent 86a30ad commit ef29c69

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This part of the configuration concerns anything that can affect the whole site.
3636
- `{provider: 'clarity', projectId: '<your-clarity-id-code' }`: use [Microsoft clarity](https://clarity.microsoft.com/). The project id can be found on top of the overview page.
3737
- `{ provider: 'matomo', siteId: '<your-matomo-id-code', host: 'matomo.example.com' }`: use [Matomo](https://matomo.org/), without protocol.
3838
- `{ provider: 'vercel' }`: use [Vercel Web Analytics](https://vercel.com/docs/concepts/analytics).
39+
- `{ provider: 'rybbit', siteId: 'my-rybbit-id' }` (managed) or `{ provider: 'rybbit', siteId: 'my-rybbit-id', host: 'my-rybbit-domain.com' }` (self-hosted) use [Rybbit](https://rybbit.com);
3940
- `locale`: used for [[i18n]] and date formatting
4041
- `baseUrl`: this is used for sitemaps and RSS feeds that require an absolute URL to know where the canonical 'home' of your site lives. This is normally the deployed URL of your site (e.g. `quartz.jzhao.xyz` for this site). Do not include the protocol (i.e. `https://`) or any leading or trailing slashes.
4142
- This should also include the subpath if you are [[hosting]] on GitHub pages without a custom domain. For example, if my repository is `jackyzha0/quartz`, GitHub pages would deploy to `https://jackyzha0.github.io/quartz` and the `baseUrl` would be `jackyzha0.github.io/quartz`.

quartz/cfg.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export type Analytics =
5050
| {
5151
provider: "vercel"
5252
}
53+
| {
54+
provider: "rybbit"
55+
siteId: string
56+
host?: string
57+
}
5358

5459
export interface GlobalConfiguration {
5560
pageTitle: string

quartz/plugins/emitters/componentResources.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
241241
vercelInsightsScript.defer = true
242242
document.head.appendChild(vercelInsightsScript)
243243
`)
244+
} else if (cfg.analytics?.provider === "rybbit") {
245+
componentResources.afterDOMLoaded.push(`
246+
const rybbitScript = document.createElement("script");
247+
rybbitScript.src = "${cfg.analytics.host ?? "https://app.rybbit.io"}/api/script.js";
248+
rybbitScript.setAttribute("data-site-id", "${cfg.analytics.siteId}");
249+
rybbitScript.async = true;
250+
rybbitScript.defer = true;
251+
252+
document.head.appendChild(rybbitScript);
253+
`)
244254
}
245255

246256
if (cfg.enableSPA) {

0 commit comments

Comments
 (0)