贵组织要求您针对 Google Analytics(分析)4 和 Google Ads 转化跟踪实现 Google 的 Consent Mode API。您已经在网络容器中使用社区模板在网站上部署了 Cookie 横幅。
您需要确保当用户同意使用 Google Ads (ad_storage) Cookie 和 Google Analytics(分析)(analytics_storage) Cookie 时,会触发 Google Ads 代码和 Google Analytics(分析)代码。如果用户拒绝使用 Google Ads Cookie 或 Google Analytics(分析)Cookie,代码应始终向其目标页面发送不使用 Cookie 的 ping。
[null,null,["最后更新时间 (UTC):2024-04-17。"],[[["\u003cp\u003eThis guide explains how to implement Google's Consent Mode with server-side tagging in Google Tag Manager for developers with existing consent solutions.\u003c/p\u003e\n"],["\u003cp\u003eConsent Mode allows Google tags to dynamically adjust their behavior based on user consent for cookies and app identifiers, respecting user privacy choices.\u003c/p\u003e\n"],["\u003cp\u003eServer-side tagging with Consent Mode requires a web container to collect consent and a server container to process data and fire tags according to the consent signals.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Analytics 4 and Google Ads tags can function with limited functionality even when users deny cookie consent by using cookieless pings and alternative tracking methods.\u003c/p\u003e\n"],["\u003cp\u003eAdvanced Consent Mode offers more granular control over tag behavior based on regional settings and user consent preferences.\u003c/p\u003e\n"]]],["Consent mode communicates user cookie or app identifier consent to Google, enabling tags to adjust behavior accordingly. It requires a consent solution, Google Tag Manager, and a GA4 client in the server container. User consent choices are sent from the website's consent banner to the Google tag, which then passes them to the server container. Tags in the server container modify data sending based on user preferences; you only need to set up consent mode in the web container. Advanced mode and region-specific setting are also supported.\n"],null,["# Implement consent mode with server-side Tag Manager\n\n\u003e This document is for developers who already have a consent solution\n\u003e implemented on their website and want to use consent mode in a server-side\n\u003e environment.\n\nWhat is consent mode?\n---------------------\n\nConsent mode lets you communicate your users' cookie or app identifier consent\nstatus to Google. Tags adjust their behavior and respect users' choices. Consent\nmode does not provide a consent banner or widget. Rather, it interacts with your\nConsent Management Platform (CMP).\n\nFor an in-depth introduction to consent mode, read [Consent mode on websites and\nmobile apps](https://support.google.com/analytics/answer/9976101)\n\nTo implement consent mode you need:\n\n- Administrator access to the Google product(s) you want to configure\n- A consent solution or cookie banner on your website that is compatible with Google's consent mode API or gtag.js\n- A Google Tag Manager [web\n container](https://support.google.com/tagmanager/answer/6103696) and a [server\n container](https://developers.google.com/tag-manager/serverside/overview).\n- A [**Google Analytics: GA4**](/tag-platform/tag-manager/server-side/send-data#client_configuration) client in the server container to receive consent data\n\nHow consent mode works with server-side tagging\n-----------------------------------------------\n\n1. The consent banner on your website receives the user's consent choices and\n sends them to the Google tag.\n\n2. The Google tag sends the user's preferences to the server container by\n adding consent parameters to the HTTP request.\n\n3. Google product tags in the server are consent-aware and adjust the\n amount and kind of data they send based on the user's preferences.\n\n| **Key Point:** Because of this architecture, **you only need to set up consent mode\n| in the web container**.\n\n### Advanced consent mode\n\nServer containers support both the [basic and advanced consent\nmode](https://support.google.com/analytics/answer/9976101#aivsbi1).\n\nWhen you have implemented advanced consent mode in your web container and work\nwith region-specific settings, set up your tagging server to support\n[region-specific settings](/tag-platform/tag-manager/server-side/enable-region-specific-settings).\n\n[Set up consent mode\n→](/tag-platform/devguides/consent#tag-manager)\n\n### Example\n\nYour organization asks you to implement Google's consent mode API for Google\nAnalytics 4 and Google Ads conversion tracking. You already have a cookie banner\non the website, which you deployed by using a community template in the web\ncontainer.\n\nYou need to make sure that your Google Ads and Google Analytics tags fire when\nthe user accepts Ads (`ad_storage`) and Analytics (`analytics_storage`) cookies.\nWhen the user rejects Ads or Analytics cookies, the tags should always send\ncookie-less\n\nto their destinations.\n\nTo implement consent mode with server-side tagging, you need the following\ncomponents: \n\n### Web container (client-side)\n\n- **Cookie banner** - Asks for consent to store cookies for Google Ads and Google Analytics. Updates consent status if user decides otherwise.\n- **Google tag** - Initializes the Google Analytics 4 library in the browser and sends data to the server container.\n\n### Server container (server-side)\n\n- Client: **Google Analytics: GA4 client** - to interpret incoming HTTP requests from the web container.\n- Tag: **Conversion Linker** - to measure conversions.\n- Tag: **Google Ads Conversion Tracking** - to send conversion data to Google Ads\n\nHow consent settings influence tag behavior\n-------------------------------------------\n\nThe following tabs explain how certain tags behave in the context of consent\nmode.\n\n### Google Analytics 4\n\n#### Tag behavior\n\n- `analytics_storage: granted` - Google Analytics 4 works normally.\n- `analytics_storage: denied`\n - **Consent mode (basic implementation)**: Google tags are fully blocked (i.e. don't load) as long as a user has not consented to Analytics cookies. No Analytics cookies are set, accessed, or read from the device, both on the client and server.\n - **Consent mode (advanced implementation)**: Google tags load on every page regardless of consent state. Google tags adjust their behavior based on user cookie consent choices using consent mode commands. When a user denies ad_storage, a cookieless ping is sent to Google Analytics. Cookieless pings are anonymous and non-identifiable Google Analytics events. No Analytics cookies are set, accessed, or read from the device, both on the client and server.\n\n#### Supported features\n\n- URL passthrough: Works if enabled in the client-side **Google tag**.\n- [TCF v2.0 Integration](https://support.google.com/analytics/answer/10022331): Works if enabled in the web container for the entire page. TCF strings are read to support ad personalization and Google Signals.\n\n### Google Ads Conversions\n\n#### Prerequisite\n\nIn order for this tag to work, you need to install the Conversion Linker\ntag in the server container.\n\n#### Tag behavior\n\n- `ad_storage: granted` - Google Ads Conversions tags work normally.\n- `ad_storage: denied` - Google Ads cookies aren't written or read. Instead, the browser sends a conversion pixel to a cookieless domain.\n\n#### Supported features\n\n- URL Passthrough: Works if enabled in client-side **Google tag**.\n- Ads Data Redaction: Works if enabled in client-side **Google tag**.\n- [TCF\n v2.0 Integration](https://support.google.com/analytics/answer/10022331): Works if enabled in the web container for the entire page.\n- Enhanced Conversions: Works when consent is granted.\n\n### Google Ads Remarketing\n\n#### Tag behavior\n\n- `ad_storage: granted` - Google Ads Remarketing tags work normally.\n- `ad_storage: denied` - Blocks HTTP requests and cookie use.\n\n#### Supported features\n\n- URL passthrough: Not supported.\n- Ads Data Redaction: The tag doesn't send a request to store data when `ad_storage` is denied.\n- [TCF v2.0 Integration](https://support.google.com/analytics/answer/10022331): Works if enabled in the web container for the entire page.\n\n### Floodlight Counter/Sales\n\n#### Prerequisite\n\nIn order for these tags to work, you need to install the Conversion Linker\ntag in the server container.\n\n#### Tag behavior\n\n- `ad_storage: granted` - Floodlight tags work normally.\n- `ad_storage: denied` - Blocks HTTP requests and cookie use.\n\n#### Supported features\n\n- URL Passthrough: Works if enabled in client-side **Google tag**.\n- Ads Data Redaction: The tag doesn't send a request to store data when `ad_storage` is denied.\n- [TCF v2.0 Integration](https://support.google.com/analytics/answer/10022331): Works if enabled in the web container for the entire page.\n\n\u003cbr /\u003e\n\nNext steps\n----------\n\n- [Verify your consent settings work](/tag-platform/devguides/consent-debugging)\n- [Set up Google Signals](/tag-platform/tag-manager/server-side/google-signals-in-sgtm)\n- [Learn about behavioral modeling in GA4](https://support.google.com/analytics/answer/11161109)\n- [Google Ads: Check changes in conversions after implementing consent mode](https://ads.google.com/aw/conversions)"]]