Skip to content

Commit

Permalink
chore: adding matomo tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Apr 24, 2024
1 parent 0c8175c commit 7985dbf
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
25 changes: 24 additions & 1 deletion docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export default {
},
],
],

customFields: {
MATOMO_CONTAINER: process.env.MATOMO_CONTAINER, // not really a secret, it's in the footer anyway
},
themeConfig: {
colorMode: {
respectPrefersColorScheme: true,
Expand Down Expand Up @@ -148,6 +150,27 @@ export default {
};
},
}),
() => ({
name: 'gdpr-cookie-consent',
injectHtmlTags({ content }) {
return {
headTags: [
{
tagName: 'div',
attributes: {
id: 'matomo-opt-out',
},
},
{
tagName: 'script',
attributes: {
src: 'https://noirlang.matomo.cloud/index.php?module=CoreAdminHome&action=optOutJS&divId=matomo-opt-out&language=auto&backgroundColor=FFFFFF&fontColor=000000&fontSize=16px&fontFamily=Roboto&showIntro=1',
},
},
],
};
},
}),
[
'docusaurus-plugin-typedoc',
{
Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"clean": "rm -rf ./processed-docs ./processed-docs ./build",
"version::stables": "ts-node ./scripts/setStable.ts",
"serve": "serve build",
"swizzle": "docusaurus swizzle",
"version": "yarn version::stables && ./scripts/cut_version.sh"
},
"dependencies": {
Expand Down
24 changes: 24 additions & 0 deletions docs/src/components/Matomo/matomo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEffect } from 'react';

import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useIsBrowser from '@docusaurus/useIsBrowser';

export default function useMatomo() {
const { siteConfig } = useDocusaurusContext();
const useIsBrowserValue = useIsBrowser();
if (!useIsBrowserValue) return null;

useEffect(() => {
console.log(siteConfig.customFields.MATOMO_CONTAINER);
var _mtm = (window._mtm = window._mtm || []);
_mtm.push({ 'mtm.startTime': new Date().getTime(), event: 'mtm.Start' });
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = `https://cdn.matomo.cloud/noirlang.matomo.cloud/container_${siteConfig.customFields.MATOMO_CONTAINER}.js`;
s.parentNode.insertBefore(g, s);
}, [window.location.href]);

return null;
}
2 changes: 1 addition & 1 deletion docs/src/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { lazy, Suspense } from 'react';
import React, { useEffect, lazy, Suspense } from 'react';
import Layout from '@theme/Layout';
import Link from '@docusaurus/Link';

Expand Down
13 changes: 13 additions & 0 deletions docs/src/theme/Footer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import Footer from '@theme-original/Footer';
import useMatomo from '@site/src/components/Matomo/matomo';

export default function FooterWrapper(props) {
useMatomo();

return (
<>
<Footer {...props} />
</>
);
}

0 comments on commit 7985dbf

Please sign in to comment.