簡體   English   中英

如何在重定向之前觸發GTM標簽?

[英]How can I fire GTM tags before redirecting?

我的Google跟蹤代碼管理器和javascript重定向的頁面空白。 這樣的想法是,用戶將通過該頁面,GTM標簽將被觸發,然后將它們重定向。

我遇到的問題是,盡管使用了DOMContentLoaded ,但標簽似乎並未及時觸發。 如果我刪除重定向,它們會觸發。

我的代碼如下所示:

<html>
  <head>
    <meta name="robots" content="noindex" />
    <title>
      <%= @destination %>
    </title>
    <%= @head_tags |> raw %>
  </head>
  <body>
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TPHDQF4"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->    
    <script>
    document.addEventListener("DOMContentLoaded", function(event) {
      window.location.href = "<%= @destination %>";
    });
    </script>
  </body>
</html>

我如何等到GTM代碼觸發后才能重定向?

GTM支持標記觸發的回調,因此您可以將重定向推送到回調中。 這是一個示例https://www.simoahava.com/gtm-tips/hitcallback-eventcallback/

暫無
暫無

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

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