• 首页
  • 技术博客
  • 作品集
  • 留言墙
  • 合作咨询

动态更新

喜欢我的内容的话不妨订阅支持一下 🫶
加入其他 0 位订阅者,每月一封,随时可以取消订阅。

© 2025 Cali Castle. 网站已开源:GitHub

首页技术博客作品集留言墙合作咨询
总浏览量 26.9万
最近访客来自 Ashburn, US🇺🇸
  • 专为 Cursor 优化的 Cookie Consent Mode v2 提示词(自动适配网站风格)
自动生成一个完整的、合规的 Google Consent Mode v2 实现模板,包括 HTML、CSS 和 JavaScript,全干净结构。
2025/05/14

自动生成一个完整的、合规的 Google Consent Mode v2 实现模板,包括 HTML、CSS 和 JavaScript,全干净结构。

打包成一份专业且易用的 Cursor Prompt,让你一贴就能让 Cursor 自动生成一个完整的、合规的 Google Consent Mode v2 实现模板,包括 HTML、CSS 和 JavaScript,全干净结构。

17次点击0分钟阅读

专为 Cursor 优化的 Cookie Consent Mode v2 提示词(自动适配网站风格)

markdownCopyEditI want to add a fully functional Cookie Consent banner that uses Google Consent Mode v2 and matches the visual style of my current website. Here’s what I need: --- ✅ Core functionality: 1. Use `gtag.js` to set default consent values: ```js ad_storage: 'denied', analytics_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied'

  1. Include wait_for_update, ads_data_redaction, and url_passthrough options.
  2. Load the Google Tag correctly:
    • Define window.dataLayer and gtag first.
    • Set consent before any gtag('config').

✅ Cookie banner behavior:

  • Show the banner only on first visit (based on localStorage).
  • Include two buttons: “Accept” and “Reject”.
  • Clicking either one:
    • Calls gtag('consent', 'update', ...)
    • Saves the choice to localStorage
    • Hides the banner
  • Also add a small “Manage Cookie Preferences” button for resetting choice.

✅ Style and integration:

This is important:
Make sure the banner inherits my site’s existing style:

  • Use the same colors, fonts, button styles, spacing, and rounded corners
  • Position the banner where it feels natural on my site (bottom, floating, etc.)
  • Match typography and visual hierarchy
  • Make it responsive like the rest of the site

If I’m using a CSS framework (like Tailwind, Bootstrap, etc.), reuse existing classes from the project.

✅ Structure:

  • Use plain HTML + JS unless my project uses a framework (you can infer from current code).
  • Wrap all JS inside DOMContentLoaded to avoid DOM loading issues.
  • Add comments explaining each part.

Make the code clean and ready to paste directly into my project.

yamlCopyEdit --- ## 🧩 使用说明: - 打开 Cursor 的 Chat 面板(Cmd + K) - 粘贴上面这个提示词 - 它会自动「读懂你项目的风格」,用当前页面/组件的配色、按钮结构来生成弹窗 UI --- ## 📌 小建议(让 Cursor 发挥最大效果): - 在你已有代码文件中运行这个提示(比如你的主页 HTML 或 layout) - 不要在空文件用,Cursor 才能“看到你网站的真实风格” --- 你现在用这版提示词,就能让 Cursor 自动做出一个既合规又长得像你网站亲兄弟的 Cookie 弹窗。