我的网站是通过VuePress生成的,现在我想添加Google Analytics(分析)。但是,使用GDPR之前,我必须先征得我的网站访问者的同意。 对于其他非vuepress网站,我正在使用metomic.io的Cookie对话来自动阻止我网站上的所有脚本,直到获得同意为止。 通常,这会阻止通过gtag.js或gtm添加Google Analytics(分析)后运行。
但是,此自动阻止功能不适用于VuePress官方插件(@vuepress/plugin-google-analytics)。我猜vuepress会在自定义脚本之前构建插件,即使我已按如下所示订购它们。
在获得GDPR同意之前,有什么方法可以阻止Google Analytics(分析)在Vuepress中运行?
/* .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
}]
],
…
答案 0 :(得分:0)
最终可行的方法是删除 @ vuepress / plugin-google-analytics ,并将gtag.js脚本手动添加到 config.js / module.exports / head 中。直到获得同意后,我的分析仪表板中才会显示流量。
只需确保在tomic dashboard/autoblocking内部启用Google的自动阻止功能之前,先添加metomic.io脚本。
我的帖子听起来非常像一个拟声广告,但我仍然希望听到其他工具和方法。与其他主题相比,我发现Google在GDPR上提供的资源很少是很有趣的。
/* .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'
}],
['script', {
async: true,
src: 'https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X'
}],
['script', {}, `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
`],
…
],
/* removed @vuepress/plugin-google-analytics'*/
…