Search code examples
jqueryhtmlonclickhrefdouble-click-advertising

Google DoubleClick onclick event goog_report_conversion always opens hyperlink with target="_blank" in current AND new tab


I have this URL:

<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>

When I click this link, it opens in a new tab, but at the same time also opens in the existing tab.

When I remove the onclick attribute, like below, it worked correctly:

<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>

I tried removing the productclick function in the onclick event, the problem persists. But when I remove the goog_report_conversion and keep the productclick function in the onclick, the problem is gone. It seems the problem really is related to the goog_report_conversion call. I get no errors in the console or network tab.

I also tried removing the onclick event altogether and run the onclick code in a jQuery onclick event, but even then the link opens in the same tab AND a new tab.

How can I make sure the link does not also open in the current tab?


Solution

  • The reason why the issue is happening is because the goog_report_conversion calls the target url once we click the link

    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
          }
        }
    

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

    It was designed like that so the links can be tracked. Once you move to a new window it's not possible to track that link.

    So the issue can't be resolved just by some hack. If you change the goog_report_conversion code then your calls won't be tracked.

    What you need to do is use Google Tag manager which will track the events.

    Update: Found a link which describes the same

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