Skip to content

Commit 648440f

Browse files
chore(website): add google tracking
1 parent 38e5d69 commit 648440f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

packages/overmind-website/backend/index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,26 @@ app.get('/backend/search', (req, res) => {
135135

136136
res.send(hits.slice(0, 5))
137137
})
138-
app.get('/*', (_, res) =>
139-
res.sendFile(path.join(__dirname, '..', 'dist', 'index.html'))
140-
)
138+
139+
let indexHtml = fs.readFileSync(path.join(__dirname, 'index.html'))
140+
141+
if (IS_PRODUCTION) {
142+
indexHtml = indexHtml.replace(
143+
'</body>',
144+
`
145+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-129590749-1"></script>
146+
<script>
147+
window.dataLayer = window.dataLayer || [];
148+
function gtag(){dataLayer.push(arguments);}
149+
gtag('js', new Date());
150+
151+
gtag('config', 'UA-129590749-1');
152+
</script>
153+
</body>
154+
`
155+
)
156+
}
157+
158+
app.get('/*', (_, res) => res.send(indexHtml))
141159

142160
app.listen(process.env.PORT || 5000, () => console.log('Server started!'))

packages/overmind-website/examples/templates.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Overmind, TConfig } from 'overmind'
1818
import { TConnect, createConnect } from 'overmind-${view}'
1919
${config.trim()}
2020
21+
// For explicit typing check the Typescript guide
2122
declare module 'overmind' {
2223
interface IConfig extends TConfig<typeof config> {}
2324
}

0 commit comments

Comments
 (0)