Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Apr 30, 2024
1 parent f414961 commit 78f0321
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
10 changes: 4 additions & 6 deletions docs/src/components/Matomo/matomo.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useEffect, useState } from 'react';

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

function getSiteId(siteConfig) {
const env = siteConfig.customFields.MATOMO_ENV;
Expand All @@ -16,12 +14,10 @@ function getSiteId(siteConfig) {

export default function useMatomo() {
const { siteConfig } = useDocusaurusContext();
const useIsBrowserValue = useIsBrowser();

const [isOptedOut, setIsOptedOut] = useState(false);
window._paq = window._paq || [];

useEffect(() => {
window._paq = window._paq || [];
console.log('effect');
console.log(window);

Expand All @@ -42,10 +38,12 @@ export default function useMatomo() {
}, []);

useEffect(() => {
window._paq = window._paq || [];
window._paq.push(['trackPageView']);
}, [window.location.href]);

useEffect(() => {
window._paq = window._paq || [];
function setOptOutText(element) {
console.log(element.checked);
window._paq.push([
Expand All @@ -70,5 +68,5 @@ export default function useMatomo() {
setOptOutText(optOut);
}, [isOptedOut]);

return null;
return <></>;
}
42 changes: 27 additions & 15 deletions docs/src/theme/Root.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import React from 'react';
import useMatomo from '@site/src/components/Matomo/matomo';
import BrowserOnly from '@docusaurus/BrowserOnly';
import useIsBrowser from '@docusaurus/useIsBrowser';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

export default function Root({ children }) {
function OptOutForm() {
useMatomo();

return (
<>
<div id="optout-form">
<p>
You may choose not to have a unique web analytics cookie identification number assigned to your computer to
avoid the aggregation and analysis of data collected on this website.
</p>
<p>To make that choice, please click below to receive an opt-out cookie.</p>
<div id="optout-form">
<p>
You may choose not to have a unique web analytics cookie identification number assigned to your computer to
avoid the aggregation and analysis of data collected on this website.
</p>
<p>To make that choice, please click below to receive an opt-out cookie.</p>

<p>
<input type="checkbox" id="optout" />
<label htmlFor="optout">
<strong></strong>
</label>
</p>
</div>
);
}

<p>
<input type="checkbox" id="optout" />
<label htmlFor="optout">
<strong></strong>
</label>
</p>
</div>
export default function Root({ children }) {
const useIsBrowserValue = useIsBrowser();
if (!useIsBrowserValue) return <>{children}</>;

return (
<>
<BrowserOnly>{() => <OptOutForm />}</BrowserOnly>
{children}
</>
);
Expand Down

0 comments on commit 78f0321

Please sign in to comment.