Skip to content

Commit 481e859

Browse files
authored
Add proxied Plausible analytics using Docosaurus (#2370)
Signed-off-by: Mihovil Ilakovac <mihovil@ilakovac.com>
1 parent 987c1d2 commit 481e859

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

web/docusaurus.config.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const lightCodeTheme = require('prism-react-renderer/themes/github')
33
const autoImportTabs = require('./src/remark/auto-import-tabs')
44
const fileExtSwitcher = require('./src/remark/file-ext-switcher')
55

6-
const includeCurrentVersion = process.env.DOCS_INCLUDE_CURRENT_VERSION === 'true'
6+
const includeCurrentVersion =
7+
process.env.DOCS_INCLUDE_CURRENT_VERSION === 'true'
8+
const isProduction = process.env.NODE_ENV === 'production'
79

810
/** @type {import('@docusaurus/types').DocusaurusConfig} */
911
module.exports = {
@@ -213,7 +215,7 @@ module.exports = {
213215
},
214216
],
215217
],
216-
scripts: ['/scripts/posthog.js', '/js/fix-multiple-trailing-slashes.js'],
218+
scripts: getScripts(),
217219
plugins: [
218220
'plugin-image-zoom',
219221
async function myPlugin(context, options) {
@@ -298,3 +300,21 @@ module.exports = {
298300
],
299301
],
300302
}
303+
304+
function getScripts() {
305+
const scripts = [
306+
'/scripts/posthog.js',
307+
'/js/fix-multiple-trailing-slashes.js',
308+
]
309+
310+
if (isProduction) {
311+
// Using Cloudflare Workers to proxy the analytics script
312+
scripts.push({
313+
src: '/waspara/wasp/script.js',
314+
defer: true,
315+
'data-domain': 'wasp-lang.dev',
316+
'data-api': '/waspara/wasp/event',
317+
})
318+
}
319+
return scripts
320+
}

web/src/pages/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ const Index = () => {
5959
content="Develop full-stack web apps without boilerplate."
6060
/>
6161
<meta property="twitter:image" content={coverPhotoAbsoluteUrl} />
62-
{/* Using Cloudflare Workers to proxy the analytics script */}
63-
<script
64-
defer
65-
data-domain="wasp-lang.dev"
66-
data-api="/waspara/wasp/event"
67-
src="/waspara/wasp/script.js"
68-
></script>
6962
</Head>
7063
<Nav />
7164
<div className="min-h-screen">

0 commit comments

Comments
 (0)