【问题标题】:Google DoubleClick onclick event goog_report_conversion always opens hyperlink with target="_blank" in current AND new tabGoogle DoubleClick onclick 事件 goog_report_conversion 始终在当前和新选项卡中打开带有 target="_blank" 的超链接
【发布时间】:2017-10-31 12:38:20
【问题描述】:

我有这个网址:

<a rel="external nofollow" href="http://prf.hn/click/camref:1101l337I/creativeref:1101l14808/destination:https://www.wehkamp.nl/Winkelen/KenmerkAdviseurArtikel.aspx?CC=C50&amp;SC=IUB&amp;KAC=C76&amp;artikelNummer=766344&amp;MaatCode=0000&amp;BC=PHGBaby_766344&amp;utm_campaign=affiliates_productfeed_Fiets_Baby&amp;dfw_tracker=22685-86766344" onclick="goog_report_conversion ('http://prf.hn/click/camref:1101l337I/creativeref:1101l14808/destination:https://www.wehkamp.nl/Winkelen/KenmerkAdviseurArtikel.aspx?CC=C50&amp;SC=IUB&amp;KAC=C76&amp;artikelNummer=766344&amp;MaatCode=0000&amp;BC=PHGBaby_766344&amp;utm_campaign=affiliates_productfeed_Fiets_Baby&amp;dfw_tracker=22685-86766344');productclick(3374956,'85-86766344');return true;" target="_blank" class="btn-primary-green" style="font-size:14px;">Shop now <i class="fa fa-chevron-right"></i></a>

当我点击此链接时,它会在新标签页中打开,但同时也会在现有标签页中打开。

当我删除 onclick 属性时,如下所示,它工作正常:

<a rel="external nofollow" href="http://prf.hn/click/camref:1101l337I/creativeref:1101l14808/destination:https://www.wehkamp.nl/Winkelen/KenmerkAdviseurArtikel.aspx?CC=C50&amp;SC=IUB&amp;KAC=C76&amp;artikelNummer=766344&amp;MaatCode=0000&amp;BC=PHGBaby_766344&amp;utm_campaign=affiliates_productfeed_Fiets_Baby&amp;dfw_tracker=22685-86766344" target="_blank" class="btn-primary-green" style="font-size:14px;">Shop now <i class="fa fa-chevron-right"></i></a>

我尝试在 onclick 事件中删除productclick 函数,问题仍然存在。但是当我删除goog_report_conversion 并在onclick 中保留productclick 功能时,问题就消失了。看来问题确实与goog_report_conversion 通话有关。我在控制台或网络选项卡中没有收到任何错误。

我还尝试完全删除 onclick 事件并在 jQuery onclick 事件中运行 onclick 代码,但即便如此,链接也会在同一个选项卡和一个新选项卡中打开。

如何确保链接不会在当前选项卡中打开?

【问题讨论】:

    标签: jquery html onclick href double-click-advertising


    【解决方案1】:

    问题发生的原因是我们点击链接后goog_report_conversion调用了目标url

    goog_report_conversion = function(url) {
          goog_snippet_vars();
          window.google_conversion_format = "3";
          var opt = new Object();
          opt.onload_callback = function() {
          if (typeof(url) != 'undefined') {
            window.location = url; // <--- this will load the url to be tracked again after the click
          }
        }
    

    参考: https://support.google.com/adwords/answer/6331304?hl=en

    它是这样设计的,因此可以跟踪链接。一旦您移动到新窗口,就无法跟踪该链接。

    所以这个问题不能仅仅通过一些 hack 来解决。如果您更改 goog_report_conversion 代码,那么您的呼叫将不会被跟踪。

    你需要做的是使用谷歌标签管理器来跟踪事件。

    更新:找到一个描述相同的链接

    https://www.en.advertisercommunity.com/t5/AdWords-Tracking-and-Reporting/Conversion-tracking-onclick-when-it-opens-a-new-window/td-p/444548#

    【讨论】:

    • 我打算在评论中提到that,但是在有问题的测试页面上,如果我删除goog_report_conversion()的参数,我仍然会得到不良影响(重定向当前页面+打开在新标签中)......所以我认为可能会有更多的游戏。或者也许我的测试无效......无论如何,我认为你会感兴趣。
    • 你是如何删除参数的?来自开发者工具?
    • 是的......也许在这种情况下这不是一个有效的方法? (如果无效或不相关,我可以删除我的 cmets,如果您认为这会引起混淆)
    • @HuguesMoreau 你可以在这里玩jsfiddle.net/karthick6891/g01cbcof。将 alert('hi') 修改为其他内容,您将首先看到 'Hi' 打印,然后是新的处理程序
    • 哇...我以为只有一个“内联 onclick”侦听器。事实上,在 DOM 中编辑它只会添加一个新的。但是,如果我在 JS 控制台中获得了链接元素的句柄,则执行link.onclick=null,然后执行link.onclick="productclick(2725086,'24-10100934');goog_report_conversion();return true;" 它可以工作:旧的侦听器消失了,新的选项卡打开了,当前页面没有重新定位。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2014-02-23
    • 1970-01-01
    • 2016-01-20
    相关资源
    最近更新 更多