From d03fdc235a7926eed5ad127ffb9c4a5f9c1008b7 Mon Sep 17 00:00:00 2001 From: John Bowdre <61015723+jbowdre@users.noreply.github.com> Date: Mon, 6 May 2024 11:30:21 -0500 Subject: [PATCH] feat(analytics): Tinylytics support (#1118) * add tinylytics support * fix formatting * add trailing semicolon for consistency --- docs/configuration.md | 3 ++- quartz/cfg.ts | 4 ++++ quartz/plugins/emitters/componentResources.ts | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 1408f71..6c4c928 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -28,8 +28,9 @@ This part of the configuration concerns anything that can affect the whole site. - `{ provider: 'google', tagId: '' }`: use Google Analytics; - `{ provider: 'plausible' }` (managed) or `{ provider: 'plausible', host: '' }` (self-hosted): use [Plausible](https://plausible.io/); - `{ provider: 'umami', host: '', websiteId: '' }`: use [Umami](https://umami.is/); - - `{ provider: 'goatcounter', websiteId: 'my-goatcounter-id' }` (managed) or `{ provider: 'goatcounter', websiteId: 'my-goatcounter-id', host: 'my-goatcounter-domain.com', scriptSrc: 'https://my-url.to/counter.js' }` (self-hosted) use [GoatCounter](https://goatcounter.com) + - `{ provider: 'goatcounter', websiteId: 'my-goatcounter-id' }` (managed) or `{ provider: 'goatcounter', websiteId: 'my-goatcounter-id', host: 'my-goatcounter-domain.com', scriptSrc: 'https://my-url.to/counter.js' }` (self-hosted) use [GoatCounter](https://goatcounter.com); - `{ provider: 'posthog', apiKey: '', host: '' }`: use [Posthog](https://posthog.com/); + - `{ provider: 'tinylytics', siteId: '' }`: use [Tinylytics](https://tinylytics.app/); - `locale`: used for [[i18n]] and date formatting - `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. - 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`. diff --git a/quartz/cfg.ts b/quartz/cfg.ts index 09905e9..13fb516 100644 --- a/quartz/cfg.ts +++ b/quartz/cfg.ts @@ -30,6 +30,10 @@ export type Analytics = apiKey: string host?: string } + | { + provider: "tinylytics" + siteId: string + } export interface GlobalConfiguration { pageTitle: string diff --git a/quartz/plugins/emitters/componentResources.ts b/quartz/plugins/emitters/componentResources.ts index 81d3af2..e6725d9 100644 --- a/quartz/plugins/emitters/componentResources.ts +++ b/quartz/plugins/emitters/componentResources.ts @@ -136,6 +136,14 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso posthog.init('${cfg.analytics.apiKey}',{api_host:'${cfg.analytics.host ?? "https://app.posthog.com"}'})\` document.head.appendChild(posthogScript) `) + } else if (cfg.analytics?.provider === "tinylytics") { + const siteId = cfg.analytics.siteId + componentResources.afterDOMLoaded.push(` + const tinylyticsScript = document.createElement("script") + tinylyticsScript.src = "https://tinylytics.app/embed/${siteId}.js" + tinylyticsScript.defer = true + document.head.appendChild(tinylyticsScript) + `) } if (cfg.enableSPA) {