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

如何在Tag Manager中设置触发器阻止再营销代码在首页触发

Hey there! Setting up your remarketing code to skip the homepage but fire on every other page is a straightforward tweak—let's break this down for both tag management tools (the most common approach) and direct code embedding:

Core Concept

The key is to add a condition that checks if the current page is your homepage. If it's not, the remarketing code triggers; if it is, the code stays inactive.

1. Using Google Tag Manager (GTM)

GTM makes this super easy with trigger exceptions:

  • Step 1: Create a page view trigger that excludes the homepage
    • Head to your GTM workspace, go to the Triggers section, and click New.
    • Select the Page View trigger type. Start with the "All Pages" option as the base.
    • Switch to the Exceptions tab, then add a new exception rule:
      • Choose Page Path as the variable, set the match type to Equals, and enter your homepage path (usually / for root domains, or /index.html if that's your homepage file).
      • Alternatively, if your homepage has a unique title, you can use Page Title equals "[Your Homepage Title]" as the exception.
    • Name the trigger something like "All Pages (Exclude Homepage)" and save it.
  • Step 2: Attach your remarketing code to this trigger
    • Go to the Tags section, create a new tag, and paste your remarketing code (or use a pre-built template like Google Ads Remarketing).
    • Under Triggering, select the "All Pages (Exclude Homepage)" trigger you just made.
    • Save the tag, then submit and publish your GTM container to make the changes live.

2. Direct Code Embedding (No Tag Manager)

If you're adding the code directly to your site's HTML, use a simple JavaScript check to skip the homepage:

// Get the current page's path
const currentPagePath = window.location.pathname;

// Check if we're NOT on the homepage (adjust the path to match your actual homepage)
if (currentPagePath !== '/') {
  // Paste your full remarketing code inside this block
  (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','GTM-XXXXXXX');
}
  • Note: If your site has multiple homepage URLs (e.g., / and /home), update the condition to:
    if (!['/', '/home'].includes(currentPagePath)) {
      // Your remarketing code here
    }
    

Quick Testing Tip

Always verify the setup:

  • For GTM, use the Preview mode to check if the tag fires on non-homepage pages and stays inactive on the homepage.
  • For direct code, inspect your homepage's page source or use browser dev tools to confirm the remarketing code isn't loaded there.

内容的提问来源于stack exchange,提问作者Harshad Methrath

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:35:25