From 481e85901b4b03cafcf51ffe5962d4f60693d633 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Thu, 14 Nov 2024 17:00:28 +0100 Subject: [PATCH] Add proxied Plausible analytics using Docosaurus (#2370) Signed-off-by: Mihovil Ilakovac --- web/docusaurus.config.js | 24 ++++++++++++++++++++++-- web/src/pages/index.js | 7 ------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/web/docusaurus.config.js b/web/docusaurus.config.js index dd33d856cf..4a559436da 100644 --- a/web/docusaurus.config.js +++ b/web/docusaurus.config.js @@ -3,7 +3,9 @@ const lightCodeTheme = require('prism-react-renderer/themes/github') const autoImportTabs = require('./src/remark/auto-import-tabs') const fileExtSwitcher = require('./src/remark/file-ext-switcher') -const includeCurrentVersion = process.env.DOCS_INCLUDE_CURRENT_VERSION === 'true' +const includeCurrentVersion = + process.env.DOCS_INCLUDE_CURRENT_VERSION === 'true' +const isProduction = process.env.NODE_ENV === 'production' /** @type {import('@docusaurus/types').DocusaurusConfig} */ module.exports = { @@ -213,7 +215,7 @@ module.exports = { }, ], ], - scripts: ['/scripts/posthog.js', '/js/fix-multiple-trailing-slashes.js'], + scripts: getScripts(), plugins: [ 'plugin-image-zoom', async function myPlugin(context, options) { @@ -298,3 +300,21 @@ module.exports = { ], ], } + +function getScripts() { + const scripts = [ + '/scripts/posthog.js', + '/js/fix-multiple-trailing-slashes.js', + ] + + if (isProduction) { + // Using Cloudflare Workers to proxy the analytics script + scripts.push({ + src: '/waspara/wasp/script.js', + defer: true, + 'data-domain': 'wasp-lang.dev', + 'data-api': '/waspara/wasp/event', + }) + } + return scripts +} diff --git a/web/src/pages/index.js b/web/src/pages/index.js index 8cc08bb162..e55b1f156d 100644 --- a/web/src/pages/index.js +++ b/web/src/pages/index.js @@ -59,13 +59,6 @@ const Index = () => { content="Develop full-stack web apps without boilerplate." /> - {/* Using Cloudflare Workers to proxy the analytics script */} -