如何在shopify中使用谷歌分析来跟踪未绑定的链接


How to track the unbound links using google analytics in shopify

我有一个Shopify商店,我正在尝试跟踪我网站的出站链接。

甚至我也找到了一些代码。

<script>
   $(document).ready(function(){
   var localserver = "trendsnaps.com";
   $("a").not("a[href^='http://"+localserver+"']").not("a[href^='https://"+localserver+"']").click(function(){
     $(this).attr("target", "blank");
     ga('send', 'event', 'links', 'click', $(this).attr('href'));
  });
   });
 </script>

但此代码仅跟踪"href"链接。我想存储提交按钮输出链接。

我的提交按钮代码是

<input class="btn add-to-cart-btn" onclick="window.open('{{ product.metafields.google.custom_label_0 }}');" type="submit" value="More Info At {{ product.vendor }}"/>

"product.metafields.google.custom_label_0"是一个外部静态链接。

我怎样才能用同样的方式追踪这些链接。

您可以将另一个函数链接到onclick处理程序

<input class="btn add-to-cart-btn" onclick="ga('send', 'event', 'links', ...);  window.open('{{ product.metafields.google.custom_label_0 }}');"...>