Skip to content

Commit

Permalink
feat: Conditional analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed Jun 6, 2024
1 parent fd04c1d commit 159774a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/backend/app/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import path from "path";
const appService = createPlugin(async (fastify) => {
const renderPage = async (reply: FastifyReply): Promise<void> => {
return reply.header("X-Frame-Options", "SAMEORIGIN").view("index.html", {
VRITE_CLOUD: process.env.VRITE_CLOUD,
PUBLIC_APP_URL: fastify.config.PUBLIC_APP_URL,
PUBLIC_API_URL: fastify.config.PUBLIC_API_URL,
PUBLIC_COLLAB_URL: fastify.config.PUBLIC_COLLAB_URL,
Expand Down
12 changes: 12 additions & 0 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
}
}
</script>
{{#if VRITE_CLOUD}}
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-16595937003"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());

gtag("config", "AW-16595937003");
</script>
{{/if}}
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
8 changes: 5 additions & 3 deletions apps/web/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export default defineConfig(async ({ mode }) => {
plugins.push({
name: "html-transform",
transformIndexHtml(html: string) {
return html.replace(/{{(PUBLIC_.+?)}}/g, (_match, name) => {
return env[name];
});
return html
.replace(/{{(PUBLIC_.+?)}}/g, (_match, name) => {
return env[name];
})
.replace(/{{#if VRITE_CLOUD}}(?:.|\n)+?{{\/if}}/g, "");
}
});
}
Expand Down

0 comments on commit 159774a

Please sign in to comment.