Skip to content

Commit

Permalink
Add matomo configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikriemer committed Jul 19, 2023
1 parent 9e61f16 commit cec057c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
8 changes: 7 additions & 1 deletion website-v2/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
"organizationName": "apache",
"projectName": "streampipes-docs",
"scripts": [
"/js/matomo.js",
"/js/jquery-3.3.1.min.js",
"/js/buttons.js",
"/js/slick.min.js",
Expand Down Expand Up @@ -63,6 +62,7 @@ module.exports = {
]
],
"plugins": [
"./src/plugins/matomo",
"docusaurus-plugin-sass",
[
"@docusaurus/plugin-client-redirects",
Expand All @@ -81,6 +81,12 @@ module.exports = {
prism: {
additionalLanguages: ['java']
},
matomo: {
matomoUrl: '//analytics.apache.org/',
siteId: '35',
phpLoader: 'matomo.php',
jsLoader: 'matomo.js',
},
"navbar": {
"logo": {
"src": "img/sp-logo-color.png"
Expand Down
67 changes: 67 additions & 0 deletions website-v2/src/plugins/matomo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const path = require('path');

module.exports = function (context) {
const {siteConfig} = context;
const {themeConfig} = siteConfig;
const {matomo} = themeConfig || {};

if (!matomo) {
throw new Error(`Please specify 'matomo' object in 'themeConfig' with 'matomoUrl' and 'siteId' fields in it to use docusaurus-plugin-matomo`);
}

const {matomoUrl, siteId} = matomo;

if (!matomoUrl) {
throw new Error('Please specify the `matomoUrl` field in the `themeConfig.matomo`');
}
if (!siteId) {
throw new Error('Please specify the `siteId` field in the `themeConfig.matomo`');
}
const phpLoader = matomo.phpLoader || 'matomo.php';
const jsLoader = matomo.jsLoader || 'matomo.js';

const isProd = process.env.NODE_ENV === 'production';

return {
name: 'docusaurus-plugin-matomo',
getClientModules() {

return isProd ? [path.resolve(__dirname, './track')] : [];
},

injectHtmlTags() {
if (!isProd) {
return {};
}
return {
headTags: [
{
tagName: 'link',
attributes: {
rel: 'preconnect',
href: `${matomoUrl}`,
},
},
{
tagName: 'script',
innerHTML: `
var _paq = window._paq = window._paq || [];
_paq.push(['setRequestMethod', 'POST']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
_paq.push(['enableHeartBeatTimer']);
(function() {
var u="${matomoUrl}";
_paq.push(['setRequestMethod', 'POST']);
_paq.push(['setTrackerUrl', u+'${phpLoader}']);
_paq.push(['setSiteId', '${siteId}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'${jsLoader}'; s.parentNode.insertBefore(g,s);
})();
`,
},
],
};
},
};
};
14 changes: 14 additions & 0 deletions website-v2/src/plugins/matomo/track.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';

export default (function () {
if (!ExecutionEnvironment.canUseDOM) {
return null;
}
return {
onRouteUpdate({location}) {
_paq.push(['setCustomUrl', location.pathname]);
_paq.push(['setDocumentTitle', document.title]);
_paq.push(['trackPageView']);
},
};
})();
2 changes: 1 addition & 1 deletion website-v2/src/theme/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const footer = {
{
icon: githubIcon,
label: 'Github Discussions',
to: 'https://github.com/apache/streampipes/issues',
to: 'https://github.com/apache/streampipes/discussions',
},
{
icon: twitterIcon,
Expand Down

0 comments on commit cec057c

Please sign in to comment.