本文介绍了导航到带有TurboLinks的页面时,不会显示Google跟踪代码管理器预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为GTM无法为我的Rails应用正确记录数据.当我使用预览功能时,开发人员工具中的GTM预览数据仅在初始页面加载时显示,后续页面加载(使用涡轮链接)不显示预览数据.我应该如何使用TurboLinks设置GTM?

I don't think GTM is recording data correctly for my Rails app. When i use the preview feature, the GTM preview data in developer tools only shows on initial page loads, subsequent page loads (using turbolinks) do not show the preview data. How should I set up GTM with TurboLinks?

我已经在标题中设置了我的GTM,如下所示:

I have set up my GTM in the header like this:

<script>
var dataLayer = [];
(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-N7MDCP');</script>
<!-- End Google Tag Manager -->

然后在身体顶部:

<script>
<% if user_signed_in? %>
  dataLayer.push({'userID': '<%= current_user.id %>'},{'userCategory': 'User'});
<% end %>
</script>


<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N7MDCP"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->


<!-- Google Tag Manager trigger for Turbolinks -->
 <script type="text/javascript">
   var url = window.location.href;
   dataLayer.push({
     'event':'pageView',
     'virtualUrl': url
   });
 </script>
 <!-- End Google Tag Manager trigger for Turbolinks -->

推荐答案

这与预览模式如何注入调试器iframe有关.

This has to do with how the preview mode injects the debugger iframe.

它是在初始页面加载时注入的,但是由于turbolinks取代了整个正文,因此它还会从-ALL-的后续页面重新加载中删除预览面板.

It is injected on the initial page load, but since turbolinks replaced the entire body it also removes the preview panel from -ALL- subsequent page reloads.

可悲的是,它的状态几乎没有,而且对此无能为力.

It is sadly pretty much how it is and not much one can do about it.

您的GTM实现可能仍在起作用,但是Google跟踪代码管理器中的预览模式与Turbolinks页面重新加载不兼容.

Your GTM implementation is probably still working, but preview mode in Google Tag Manager is not compatible with turbolinks page reloads.

是的,这使得在turbolinks增强站点中调试GTM成为主要难题.

And yes, this makes debugging GTM in turbolinks enhanced sites a major pain.

这篇关于导航到带有TurboLinks的页面时,不会显示Google跟踪代码管理器预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:00