-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7985dbf
commit ac402fa
Showing
6 changed files
with
100 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,72 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
import useIsBrowser from '@docusaurus/useIsBrowser'; | ||
|
||
function getSiteId(siteConfig) { | ||
const env = siteConfig.customFields.MATOMO_ENV; | ||
if (env == 'dev') { | ||
return '3'; | ||
} else if (env == 'staging') { | ||
return '2'; | ||
} else { | ||
return '1'; | ||
} | ||
} | ||
|
||
export default function useMatomo() { | ||
const { siteConfig } = useDocusaurusContext(); | ||
const useIsBrowserValue = useIsBrowser(); | ||
if (!useIsBrowserValue) return null; | ||
const [isOptedOut, setIsOptedOut] = useState(false); | ||
|
||
useEffect(() => { | ||
console.log(siteConfig.customFields.MATOMO_CONTAINER); | ||
var _mtm = (window._mtm = window._mtm || []); | ||
_mtm.push({ 'mtm.startTime': new Date().getTime(), event: 'mtm.Start' }); | ||
window._paq = window._paq || []; | ||
console.log('effect'); | ||
console.log(window); | ||
|
||
var u = 'https://noirlang.matomo.cloud/'; | ||
const siteId = getSiteId(siteConfig); | ||
// const secureCookie = siteId === '3' ? false : true; | ||
// console.log('secureCookie', secureCookie); | ||
// window._paq.push(['setSecureCookie', secureCookie]); | ||
window._paq.push(['setTrackerUrl', u + 'matomo.php']); | ||
window._paq.push(['setSiteId', siteId]); | ||
|
||
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`; | ||
g.src = 'https://cdn.matomo.cloud/noirlang.matomo.cloud/matomo.js'; | ||
s.parentNode.insertBefore(g, s); | ||
}, []); | ||
|
||
useEffect(() => { | ||
window._paq = window._paq || []; | ||
window._paq.push(['trackPageView']); | ||
}, [window.location.href]); | ||
|
||
return null; | ||
useEffect(() => { | ||
window._paq = window._paq || []; | ||
function setOptOutText(element) { | ||
console.log(element.checked); | ||
window._paq.push([ | ||
function () { | ||
element.checked = !this.isUserOptedOut(); | ||
document.querySelector('label[for=optout] strong').innerText = this.isUserOptedOut() | ||
? 'You are currently opted out. Click here to opt in.' | ||
: 'You are currently opted in. Click here to opt out.'; | ||
}, | ||
]); | ||
} | ||
|
||
var optOut = document.getElementById('optout'); | ||
optOut.addEventListener('click', function () { | ||
if (this.checked) { | ||
window._paq.push(['forgetUserOptOut']); | ||
} else { | ||
window._paq.push(['optUserOut']); | ||
} | ||
setOptOutText(optOut); | ||
}); | ||
setOptOutText(optOut); | ||
}, [isOptedOut]); | ||
|
||
return <></>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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'; | ||
|
||
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> | ||
|
||
<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} | ||
</> | ||
); | ||
} |