簡體   English   中英

cookie 同意彈出窗口如何在內部工作?

[英]How do cookie consent pop-ups work internally?

我的項目與 Google Analytics 相關聯。 現在我想在我的網站上創建一個 cookie 同意彈出窗口,以符合歐盟法規。

現在我在歐盟法規中看到用戶可以 select “允許”或“拒絕”。 然后你可以匿名化谷歌分析。 但是這在我的代碼內部是如何工作的?

我真的不知道這一切在代碼中是如何工作的,有人有例子嗎?

在互聯網上,您會找到很多關於如何創建彈出窗口的信息,但他們從未進一步了解如何在內部編寫所有內容。

Cookies 是存儲在您計算機上的網站可以訪問的文件,第 3 方 cookies 是其他網站也可以訪問的 cookies。 創建 cookie 的最基本方法是使用瀏覽器本地存儲。 您的允許/拒絕系統可以像全局存儲的真/假值一樣簡單,每次從本地存儲中獲取或存儲值時,使用 if 語句檢查是否允許 cookies。

這里有些例子。

 // This will store a value/cookie with the id "myKey" and the value "myValue" Window.localStorage.setItem("myKey", "myValue"); // You can get the value/cookie you stored earlier by using the values ID, in this case it should return "myValue" Window.localStorage.getItem("myKey"); // To delete a value/cookie do this Window.localStorage.remove("myKey"); // this is your logic to check if cookies are allowed let AreCookiesAllowed = true; if (AreCookiesAllowed === true) { // Do things with cookies Window.localStorage.setItem("theme", "dark"); }

參考資料可以在這里找到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM