Skip to content

Commit

Permalink
Added Matomo on the demo site
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgirault committed Feb 17, 2025
1 parent a8db854 commit c81b1c5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
39 changes: 39 additions & 0 deletions build/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,42 @@ export const assetsPlugin = () =>
}
]
});

export const matomoPlugin = () => {
const matomoScript = `
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://matomo.boscop.io/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '104']);
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>
`;

return {
apply(compiler) {
compiler.hooks.compilation.tap('MatomoPlugin', (compilation) => {
rspack.HtmlRspackPlugin.getCompilationHooks(
compilation
).afterTemplateExecution.tapPromise(
'MatomoPlugin',
async (data) => {
// The `alterAssetTags` hook would
// be a nicer place to that but tags
// other than `title` can't have any
// HTML contents.
data.html = data.html.replace(
'</head>',
`${matomoScript}</head>`
);
}
);
});
}
};
};
6 changes: 4 additions & 2 deletions rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const {standaloneEntries} = require('./build/entries');
const {
templatePlugin,
featureTemplatePlugin,
assetsPlugin
assetsPlugin,
matomoPlugin
} = require('./build/site');

const fullPath = path.resolve.bind(path, __dirname);
Expand Down Expand Up @@ -107,6 +108,7 @@ module.exports = {
chunks: [],
lang: 'fr'
}),
assetsPlugin()
assetsPlugin(),
matomoPlugin()
]
};

0 comments on commit c81b1c5

Please sign in to comment.