Add proxied Plausible analytics using Docosaurus (#2370)

Signed-off-by: Mihovil Ilakovac <mihovil@ilakovac.com>
This commit is contained in:
Mihovil Ilakovac 2024-11-14 17:00:28 +01:00 committed by GitHub
parent 987c1d2748
commit 481e85901b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 9 deletions

View File

@ -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
}

View File

@ -59,13 +59,6 @@ const Index = () => {
content="Develop full-stack web apps without boilerplate."
/>
<meta property="twitter:image" content={coverPhotoAbsoluteUrl} />
{/* Using Cloudflare Workers to proxy the analytics script */}
<script
defer
data-domain="wasp-lang.dev"
data-api="/waspara/wasp/event"
src="/waspara/wasp/script.js"
></script>
</Head>
<Nav />
<div className="min-h-screen">