Google Analytics(分析),Flutter,Cookie和通用数据保护法规(GDPR) [英] Google Analytics, Flutter, cookies and the General Data Protection Regulation (GDPR)
问题描述
根据通用数据保护法规(GDPR),用户必须在设置任何Cookie之前表示同意。
Following the General Data Protection Regulation (GDPR) the user has to give his consent before any cookie is set.
我在Google中使用google / firebase分析Flutter网站。当用户立即打开页面时,将存储两个cookie:_ga和_ga_SOMECODE。
I use google / firebase analytics in a Flutter web site. When the user opens a page immediately two cookies are stored: _ga and _ga_SOMECODE.
我如何使Google Analytics(分析)推迟这些cookie,以便我可以先征得用户的同意并留给他选择允许Cookie来使用Google Analytics(分析)还是拒绝两者?
How can I make google analytics postpone these cookies so that I can first ask the user's consent and leave to him the choice to allow a cookie for the use of google analytics - or to reject both?
我正在寻找这样的东西:
I am looking for something like this:
index.html中的
in index.html
// Initialize Google Analytics
<script>
var analyticsConfig = { enabled: false };
firebase.analytics(analyticsConfig);
</script>
首页上的某处:
Somewhere on the first page:
接受统计信息Cookie吗? [是] [否]
并使用相应的飞镖代码:
and in the corresponding dart code:
// Enable / disable Google Analytics
FirebaseAnalytics analytics = getAnalytics();
analytics.setAnalyticsCollectionEnabled(usersAnswer);
在理想情况下,分析代码只能当用户提供肯定答案时加载。在用户选择 [no] 的情况下,代码库中的分析代码将无效。
In the ideal case the analytics code would only be loaded when the user provided a positive answer. In the case the user's choice would be [no] the analytics code in the code base would do nothing.
我该如何实现类似的功能?
How can I implement something similar?
感谢Dietrich
Thanks, Dietrich
推荐答案
我找到了可行的解决方案:
I found a working solution:
在调用 index.html
中的 firebase.analytics()
之前,先调用变量 ga- disable-G-FOO0490BAR
必须设置为 true
-其中 G-FOO0490BAR
对应
Before calling firebase.analytics()
in index.html
the variable ga-disable-G-FOO0490BAR
has to be set to true
- where G-FOO0490BAR
corresponds to the google analytics measurement ID or the tracking ID of your project.
<script>
// Initialize Google Analytics
var measurementID = "G-FOO0490BAR";
window['ga-disable-' + measurementID] = true;
firebase.analytics();
</script>
我在Google或Firebase Analytics控制台中都找不到此ID。但是在安装并激活Google Analytics(分析)调试器插件后,发送Google Analytics(分析)事件时,Chrome浏览器控制台就会显示该插件。
I couldn't find this ID anywhere, neither in the Google nor in the Firebase Analytics console. But after installing and activating the Google Analytics Debugger plugin it was shown in the the chrome browser console when sending google analytics events.
例如:
Processing GTAG command: ["event", "test_event", {string: "Hello, World!", send_to: "G-FOO0490BAR"}]
现在,我可以使用以下代码从Flutter启用/禁用Google分析:
Now I can enable / disable google analytics from Flutter with the following code:
// Enable / disable Google Analytics
FirebaseAnalytics analytics = getAnalytics();
analytics.setAnalyticsCollectionEnabled(usersAnswer);
禁用Google Analytics(分析)时未设置Cookie。
No cookies are set when Google Analytics is disabled.
我找到了此解决方案在以下页面上:
I found this solution on the following page:
- 禁用Google Analytics(分析)测量
https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out
- Disable Google Analytics measurement https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out
可以在此处找到要使用的ID的说明:
An explanation of the ID to be used can be found here:
- 我的跟踪ID发生了什么?
https://support.google.com/analytics/answer/9539598
- What happened to my Tracking ID? https://support.google.com/analytics/answer/9539598
但是,与我在后一页写的相反,在面板右上方没有显示测量ID。
However, contrary to what is written on the latter page in my case no measurement ID was shown in the upper right portion of the panel.
迪特里克(Dietrich)干杯
Cheers, Dietrich
这篇关于Google Analytics(分析),Flutter,Cookie和通用数据保护法规(GDPR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!