mirror of
https://github.com/tlsnotary/website.git
synced 2026-01-07 21:24:15 -05:00
Added matomo tracking
This commit is contained in:
@@ -3,6 +3,7 @@ import type { Config } from '@docusaurus/types';
|
|||||||
import type * as Preset from '@docusaurus/preset-classic';
|
import type * as Preset from '@docusaurus/preset-classic';
|
||||||
import remarkMath from 'remark-math';
|
import remarkMath from 'remark-math';
|
||||||
import rehypeKatex from 'rehype-katex';
|
import rehypeKatex from 'rehype-katex';
|
||||||
|
import matomoPlugin from './plugins/matomo-plugin';
|
||||||
|
|
||||||
// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
|
// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
|
||||||
|
|
||||||
@@ -25,6 +26,9 @@ const config: Config = {
|
|||||||
onBrokenLinks: 'throw',
|
onBrokenLinks: 'throw',
|
||||||
onBrokenMarkdownLinks: 'warn',
|
onBrokenMarkdownLinks: 'warn',
|
||||||
|
|
||||||
|
|
||||||
|
plugins: [matomoPlugin],
|
||||||
|
|
||||||
// Even if you don't use internationalization, you can use this field to set
|
// Even if you don't use internationalization, you can use this field to set
|
||||||
// useful metadata like html lang. For example, if your site is Chinese, you
|
// useful metadata like html lang. For example, if your site is Chinese, you
|
||||||
// may want to replace "en" with "zh-Hans".
|
// may want to replace "en" with "zh-Hans".
|
||||||
|
|||||||
35
plugins/matomo-plugin/index.ts
Normal file
35
plugins/matomo-plugin/index.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import type { Plugin } from '@docusaurus/types';
|
||||||
|
|
||||||
|
export default function matomoHeadPlugin(): Plugin {
|
||||||
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: 'matomo-plugin',
|
||||||
|
injectHtmlTags() {
|
||||||
|
if (!isProd) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
headTags: [
|
||||||
|
{
|
||||||
|
tagName: 'script',
|
||||||
|
attributes: {
|
||||||
|
id: 'matomo-tracking',
|
||||||
|
strategy: 'afterInteractive',
|
||||||
|
},
|
||||||
|
innerHTML: `var _paq = window._paq = window._paq || [];
|
||||||
|
_paq.push(['trackPageView']);
|
||||||
|
_paq.push(['enableLinkTracking']);
|
||||||
|
(function() {
|
||||||
|
var u="https://psedev.matomo.cloud/";
|
||||||
|
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
||||||
|
_paq.push(['setSiteId', '16']);
|
||||||
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||||
|
g.async=true; g.src='//cdn.matomo.cloud/psedev.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s);
|
||||||
|
})();`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
23
src/components/MatomoHead/index.tsx
Normal file
23
src/components/MatomoHead/index.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Head from '@docusaurus/Head';
|
||||||
|
|
||||||
|
export default function MatomoHead() {
|
||||||
|
return (
|
||||||
|
<Head>
|
||||||
|
<script>
|
||||||
|
{`
|
||||||
|
var _paq = window._paq = window._paq || [];
|
||||||
|
_paq.push(['trackPageView']);
|
||||||
|
_paq.push(['enableLinkTracking']);
|
||||||
|
(function() {
|
||||||
|
var u="https://your-matomo-domain.example.com/";
|
||||||
|
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
||||||
|
_paq.push(['setSiteId', 'YOUR_SITE_ID']);
|
||||||
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||||
|
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
||||||
|
})();
|
||||||
|
`}
|
||||||
|
</script>
|
||||||
|
</Head>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user