Skip to content

Commit

Permalink
feat: track darkmode with Plausible
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpou committed Jun 4, 2024
1 parent ff78007 commit 6585928
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const { title, description, translations = [], seo } = Astro.props

<script
is:inline
async
defer
data-domain="maxpou.fr"
src="https://plausible.io/js/plausible.js"></script>
Expand Down Expand Up @@ -108,4 +107,6 @@ const { title, description, translations = [], seo } = Astro.props
document.documentElement.classList.add('dark')
}
window.localStorage.setItem('theme', theme)
typeof plausible !== 'undefined'
&& plausible('pageview', {props: {darkMode: theme !== 'light'}})
</script>
6 changes: 5 additions & 1 deletion src/components/DarkModeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export default function ThemeToggle({
)

const handleClick = () => {
setTheme(theme === 'light' ? 'dark' : 'light')
const newTheme = theme === 'light' ? 'dark' : 'light'
setTheme(newTheme)
// @ts-ignore
typeof plausible !== 'undefined' && // @ts-ignore
plausible('darkModeClick', { props: { theme: newTheme } })
}

useEffect(() => {
Expand Down

0 comments on commit 6585928

Please sign in to comment.