You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何创建Google Tag Manager触发器实现合规加载Google再营销代码

I’ve tackled this exact scenario many times—here’s a step-by-step, reliable method to get your Google Remarketing code loading only after the user accepts marketing cookies, fully compliant with GDPR:

First, you need to send a clear signal to GTM when the user agrees to marketing cookies. Modify your consent banner’s "Accept Marketing" button handler to push an event and variable to the GTM data layer once consent is given.

Add this code to your banner’s click action:

window.dataLayer = window.dataLayer || [];
dataLayer.push({
  'event': 'marketing_consent_granted',
  'allow_marketing_cookies': true
});
// Optional: Save consent to a cookie for returning visitors
document.cookie = "marketing_consent=true; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";

For returning users who’ve already consented, push the event on page load too:

// Check for existing consent cookie when the page loads
if (document.cookie.includes('marketing_consent=true')) {
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    'event': 'marketing_consent_granted',
    'allow_marketing_cookies': true
  });
}

Step 2: Create a Data Layer Variable in GTM

Set up a variable to read the consent status from the data layer:

  • Go to Variables > User-Defined Variables > New
  • Select the Data Layer Variable type
  • Set the Data Layer Variable Name to allow_marketing_cookies
  • Name the variable something clear like DL - Allow Marketing Cookies and save it

Create a trigger that only fires when consent is confirmed:

  • Go to Triggers > New
  • Choose the Custom Event trigger type
  • Set the Event Name to marketing_consent_granted (matches the event we pushed earlier)
  • Under This trigger fires on, select Some Custom Events
  • Add a condition: DL - Allow Marketing Cookies equals true
  • Name the trigger Trigger - Marketing Consent Granted and save it

Step 4: Add Your Google Remarketing Code as a Custom HTML Tag

Finally, add your remarketing code to GTM and bind it to the consent trigger:

  • Go to Tags > New
  • Select the Custom HTML tag type
  • Paste your full Google Remarketing code into the HTML field (leave out async/defer—GTM will handle loading it only when the trigger fires)
  • Under Triggering, select the Trigger - Marketing Consent Granted trigger you created
  • Name the tag Tag - Google Remarketing and save it

Testing the Setup

  • Use GTM’s Preview Mode to validate: load your site, click the consent banner’s accept button, and confirm the marketing_consent_granted event fires. Check your browser’s Network tab to ensure the remarketing script is only requested after consent.
  • For returning visitors, verify the tag loads automatically on page load if the consent cookie exists.

内容的提问来源于stack exchange,提问作者Leonida-Alexandru Diaconu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:05:02