Skip to content

Commit

Permalink
Add proxied Plausible analytics using Docosaurus (#2370)
Browse files Browse the repository at this point in the history
Signed-off-by: Mihovil Ilakovac <[email protected]>
  • Loading branch information
infomiho authored Nov 14, 2024
1 parent 987c1d2 commit 481e859
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
24 changes: 22 additions & 2 deletions web/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
7 changes: 0 additions & 7 deletions web/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 481e859

Please sign in to comment.