Ajout plugin Plausible pour analytics
This commit is contained in:
parent
e8a76dae05
commit
f30d689499
2 changed files with 59 additions and 0 deletions
|
|
@ -25,6 +25,13 @@ const config: Config = {
|
||||||
'docusaurus-plugin-image-zoom',
|
'docusaurus-plugin-image-zoom',
|
||||||
'./plugins/docusaurus-plugin-unified-tags',
|
'./plugins/docusaurus-plugin-unified-tags',
|
||||||
'./plugins/docusaurus-plugin-recent-articles',
|
'./plugins/docusaurus-plugin-recent-articles',
|
||||||
|
[
|
||||||
|
'./plugins/docusaurus-plugin-plausible-custom',
|
||||||
|
{
|
||||||
|
domain: 'docs.tellserv.fr',
|
||||||
|
scriptSrc: 'https://plausible.tellserv.fr/js/script.js',
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
title: 'TellServ Tech Blog',
|
title: 'TellServ Tech Blog',
|
||||||
|
|
|
||||||
52
plugins/docusaurus-plugin-plausible-custom.js
Normal file
52
plugins/docusaurus-plugin-plausible-custom.js
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
module.exports = function (_context, options) {
|
||||||
|
const { domain, scriptSrc } = options;
|
||||||
|
|
||||||
|
if (!domain) {
|
||||||
|
throw new Error('You must specify the `domain` option for plausible-custom plugin.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scriptSrc) {
|
||||||
|
throw new Error('You must specify the `scriptSrc` option for plausible-custom plugin.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: 'docusaurus-plugin-plausible-custom',
|
||||||
|
|
||||||
|
injectHtmlTags() {
|
||||||
|
if (!isProd) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
headTags: [
|
||||||
|
{
|
||||||
|
tagName: 'link',
|
||||||
|
attributes: {
|
||||||
|
key: 'plausible-custom-preconnect',
|
||||||
|
rel: 'preconnect',
|
||||||
|
href: new URL(scriptSrc).origin,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tagName: 'script',
|
||||||
|
attributes: {
|
||||||
|
key: 'plausible-custom-script',
|
||||||
|
defer: true,
|
||||||
|
'data-domain': domain,
|
||||||
|
src: scriptSrc,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tagName: 'script',
|
||||||
|
attributes: {
|
||||||
|
key: 'plausible-custom-events',
|
||||||
|
},
|
||||||
|
innerHTML: 'window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) };',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue