Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions news/changelog-1.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ All changes included in 1.9:
- ([#13452](https://github.com/quarto-dev/quarto-cli/issues/13452)): Wraps subfigure captions generated by `quarto_super()` in `block` function to avoid emitting `par` elements. (author: @christopherkenny)
- ([#13474](https://github.com/quarto-dev/quarto-cli/issues/13474)): Heading font for title should default to `mainfont`.

## Projects

### `website`

- Add support for Plausible Analytics via `plausible-analytics` configuration option. Users can paste their Plausible script snippet directly from their Plausible dashboard.

## `publish`

### Confluence
Expand Down
49 changes: 29 additions & 20 deletions src/project/types/website/website-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const kStorage = "storage";
const kAnonymizeIp = "anonymize-ip";
const kVersion = "version";

// Plausible analytics
export const kPlausibleAnalytics = "plausible-analytics";

// Cookie consent properties
export const kCookieConsent = "cookie-consent";
const kCookieConsentType = "type";
Expand Down Expand Up @@ -77,21 +80,19 @@ ${contents}
}
}

// Generate the script to inject into the head for Google Analytics
// Generate the script to inject into the head for Google Analytics and/or Plausible
export function websiteAnalyticsScriptFile(
project: ProjectContext,
temp: TempContext,
) {
// Find the ga tag
const siteMeta = project.config?.[kWebsite] as Metadata;

// The google analytics metadata (either from the page or the site)
// Deal with page and site options
let gaConfig: GaConfiguration | undefined = undefined;
const scripts: string[] = [];

if (siteMeta) {
// Google Analytics
let gaConfig: GaConfiguration | undefined = undefined;
const siteGa = siteMeta[kGoogleAnalytics];
if (typeof (siteGa) === "object") {
if (typeof siteGa === "object") {
const siteGaMeta = siteGa as Metadata;
// Merge the site and page options and then layer over defaults
const trackingId = siteGaMeta[kTrackingId] as string;
Expand All @@ -105,19 +106,27 @@ export function websiteAnalyticsScriptFile(
anonymizedIp,
version,
);
} else if (siteGa && typeof (siteGa) === "string") {
} else if (siteGa && typeof siteGa === "string") {
gaConfig = googleAnalyticsConfig(project, siteGa as string);
}
}

// Generate the actual GA dependencies
if (gaConfig) {
const script = analyticsScript(gaConfig);
if (script) {
return scriptFile(script, temp);
} else {
return undefined;
if (gaConfig) {
const gaScript = analyticsScript(gaConfig);
if (gaScript) {
scripts.push(gaScript);
}
}

// Plausible Analytics
const plausibleSnippet = siteMeta[kPlausibleAnalytics];
if (plausibleSnippet && typeof plausibleSnippet === "string") {
scripts.push(plausibleSnippet);
}
}

// Return combined script file if we have any analytics
if (scripts.length > 0) {
return scriptFile(scripts.join("\n"), temp);
} else {
return undefined;
}
Expand All @@ -138,7 +147,7 @@ export function cookieConsentDependencies(
let configuration: CookieConsentConfiguration | undefined = undefined;
let changePrefsText: string | undefined = undefined;
const consent = siteMeta[kCookieConsent];
if (typeof (consent) === "object") {
if (typeof consent === "object") {
const cookieMeta = consent as Metadata;
configuration = cookieConsentConfiguration(
title,
Expand Down Expand Up @@ -384,7 +393,7 @@ cookieconsent.run({
}

function scriptFile(script: string, temp: TempContext) {
const gaScriptFile = temp.createFile({ suffix: "-lytics.js" });
Deno.writeTextFileSync(gaScriptFile, script);
return gaScriptFile;
const analyticsScriptFile = temp.createFile({ suffix: "-lytics.js" });
Deno.writeTextFileSync(analyticsScriptFile, script);
return analyticsScriptFile;
}
13 changes: 10 additions & 3 deletions src/resources/editor/tools/vs-code.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9427,6 +9427,13 @@ var require_yaml_intelligence_resources = __commonJS({
],
description: "Enable Google Analytics for this website"
},
"plausible-analytics": {
schema: "string",
description: {
short: "Enable Plausible Analytics for this website",
long: "Enable Plausible Analytics for this website by pasting the script snippet from your Plausible dashboard.\n\nPlausible is a privacy-friendly, GDPR-compliant web analytics service that does not use cookies and does not require cookie consent.\n\nTo get your script snippet:\n\n1. Log into your Plausible account at <https://plausible.io>\n2. Go to your site settings\n3. Copy the JavaScript snippet provided\n4. Paste it here\n\nFor more information, see <https://plausible.io/docs/plausible-script>\n"
}
},
announcement: {
anyOf: [
"string",
Expand Down Expand Up @@ -24933,12 +24940,12 @@ var require_yaml_intelligence_resources = __commonJS({
mermaid: "%%"
},
"handlers/mermaid/schema.yml": {
_internalId: 197474,
_internalId: 197475,
type: "object",
description: "be an object",
properties: {
"mermaid-format": {
_internalId: 197466,
_internalId: 197467,
type: "enum",
enum: [
"png",
Expand All @@ -24954,7 +24961,7 @@ var require_yaml_intelligence_resources = __commonJS({
exhaustiveCompletions: true
},
theme: {
_internalId: 197473,
_internalId: 197474,
type: "anyOf",
anyOf: [
{
Expand Down

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/resources/editor/tools/yaml/web-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/resources/editor/tools/yaml/yaml-intelligence-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,13 @@
],
"description": "Enable Google Analytics for this website"
},
"plausible-analytics": {
"schema": "string",
"description": {
"short": "Enable Plausible Analytics for this website",
"long": "Enable Plausible Analytics for this website by pasting the script snippet from your Plausible dashboard.\n\nPlausible is a privacy-friendly, GDPR-compliant web analytics service that does not use cookies and does not require cookie consent.\n\nTo get your script snippet:\n\n1. Log into your Plausible account at <https://plausible.io>\n2. Go to your site settings\n3. Copy the JavaScript snippet provided\n4. Paste it here\n\nFor more information, see <https://plausible.io/docs/plausible-script>\n"
}
},
"announcement": {
"anyOf": [
"string",
Expand Down Expand Up @@ -17905,12 +17912,12 @@
"mermaid": "%%"
},
"handlers/mermaid/schema.yml": {
"_internalId": 197474,
"_internalId": 197475,
"type": "object",
"description": "be an object",
"properties": {
"mermaid-format": {
"_internalId": 197466,
"_internalId": 197467,
"type": "enum",
"enum": [
"png",
Expand All @@ -17926,7 +17933,7 @@
"exhaustiveCompletions": true
},
"theme": {
"_internalId": 197473,
"_internalId": 197474,
"type": "anyOf",
"anyOf": [
{
Expand Down
17 changes: 17 additions & 0 deletions src/resources/schema/definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,23 @@

This is automatically detected based upon the `tracking-id`, but you may specify it.
description: "Enable Google Analytics for this website"
plausible-analytics:
schema: string
description:
short: "Enable Plausible Analytics for this website by inserting scrips snippets to add in site `<head>`"
long: |
Enable Plausible Analytics for this website by pasting the script snippet from your Plausible dashboard.

Plausible is a privacy-friendly, GDPR-compliant web analytics service that does not use cookies and does not require cookie consent.

To get your script snippet:

1. Log into your Plausible account at <https://plausible.io>
2. Go to your site settings
3. Copy the JavaScript snippet provided
4. Paste it here

For more information, see <https://plausible.io/docs/plausible-script>
announcement:
anyOf:
- string
Expand Down
3 changes: 3 additions & 0 deletions src/resources/schema/json-schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,9 @@
}
]
},
"plausible-analytics": {
"type": "string"
},
"announcement": {
"anyOf": [
{
Expand Down
1 change: 1 addition & 0 deletions src/resources/types/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ For more about choosing storage options see [Storage](https://quarto.org/docs/we

This is automatically detected based upon the `tracking-id`, but you may specify it. */
} /* Enable Google Analytics for this website */;
"plausible-analytics"?: string;
"cookie-consent"?: ("express" | "implied") | boolean | {
"policy-url"?: string;
"prefs-text"?: string;
Expand Down
2 changes: 2 additions & 0 deletions src/resources/types/zod/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const ZodBaseWebsite = z.object({
version: z.union([z.literal(3), z.literal(4)]),
}).passthrough().partial(),
]),
"plausible-analytics": z.string(),
announcement: z.union([
z.string(),
z.object({
Expand Down Expand Up @@ -473,6 +474,7 @@ export const ZodBookSchema = z.object({
version: z.union([z.literal(3), z.literal(4)]),
}).passthrough().partial(),
]),
"plausible-analytics": z.string(),
announcement: z.union([
z.string(),
z.object({
Expand Down
4 changes: 0 additions & 4 deletions tests/docs/smoke-all/website/.gitignore

This file was deleted.

2 changes: 2 additions & 0 deletions tests/docs/smoke-all/website/plausible-analytics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
**/*.quarto_ipynb
11 changes: 11 additions & 0 deletions tests/docs/smoke-all/website/plausible-analytics/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project:
type: website

website:
title: "Plausible Custom Script Test"
plausible-analytics: |
<script async src="https://plausible.io/js/pa-TESTCODE123.js"></script>
<script>
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)};
plausible.init()
</script>
14 changes: 14 additions & 0 deletions tests/docs/smoke-all/website/plausible-analytics/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "Plausible Custom Script Test"
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'script[async][src="https://plausible.io/js/pa-TESTCODE123.js"]'
ensureFileRegexMatches:
- ['window\.plausible', 'plausible\.init']
---

This test verifies that Plausible Analytics with custom script (pa-XXXX.js format)
and initialization code is correctly injected into the HTML output.
5 changes: 5 additions & 0 deletions tests/docs/smoke-all/website/sidebar-content/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.quarto/
*.html
*.json
site_libs/
**/*.quarto_ipynb
Loading