My website is generated via VuePress and now I want to add Google Analytics. However, with GDPR I have to ask my website visitor for consent before using it. For other, non-vuepress, websites I am using metomic.io's cookie dialogue to autoblock all scripts on my website until consent was given. Usually this prevents Google Analytics to run when it's added via the gtag.js or gtm.
However, this autoblock does not work with the official VuePress plugin (@vuepress/plugin-google-analytics). I'm guessing vuepress builds the plugins before custom scripts even though I've ordered them as shown below.
Is there any way I can stop Google Analytics from running in Vuepress until GDPR consent was given?
/* .vuepress/config.js */
…
module.exports = {
…
head: [
['script', {
src: 'https://config.metomic.io/config.js?id=prj:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx‘,
crossorigin: 'anonymous',
charset: 'utf-8'
}],
['script', {
src: 'https://consent-manager.metomic.io/embed.js',
crossorigin: 'anonymous',
charset: 'utf-8'
}],
…
],
plugins: [
['@vuepress/plugin-google-analytics', {
'ga': '' // UA-XXXXXXXXX-X
}]
],
…