google ads conversion code

Asked

Viewed 361 times

-1

Good afternoon to all!! All right? i created a google ads conversion tag, which should be triggered by clicking on the Whatsapp link on my site, but I’m not able to install correctly on the trigger, which is the Whats button(it’s a href)...I launched an "onclick" but the girl from Goolge said that way, this wrong... I’ll post the code, will you help me? this is the global tag:

    <!-- 
    Global site tag (gtag.js) - Google Ads: ********** -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=AW- 
    **********"></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'AW-******************'); 
    </script>

Snipet is this guy who informs the click according to the google people :

     <script>
      function gtag_report_conversion(url) {
      var callback = function () {
      if (typeof(url) != 'undefined') {
      window.location = url;
      }
      };
      gtag('event', 'conversion', {
      'send_to': 'AW-***************/*******************',
      'event_callback': callback
      });
       return false;
      }
      </script>

the problem is that the trigger here is the click on a button, which is an image or text...I’m not sure how to put this code on the buttons...does anyone know? Could you help me, please? Thank you all!!! Big hug!!!

1 answer

0

have already solved this problem using JS with Jquery, thus:

    $('a[href*="whatsapp"]').click(function(){
      gtag('event', 'conversion', {
      'send_to': 'AW-***************/*******************',
      'event_callback': callback
      });

});

Briefly, by detecting in the DOM a click where href has the word Whatsapp (Whatsapp’s default API link, for example) it will call gtag.

Ah, href will request the Whatsapp address, but it gives the script time to run before loading.

Cool? I hope I helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.