How To Add FB Pixel's Code Into A Button that open Whatsapp And Ready to Send A Message

Sometimes we need to track how many clicks happened to our button as we send paid traffic to the landing page. Without knowing this we cannot optimize and cannot measure the effectiveness of our ads.
Below button when clicked will send "Lead" event to the Facebook analytic and also will open Whatsapp automatically (when opened in a mobile device with Whatsapp installed) with a predefined message to the designated number.
This is the code:
<h4>
<button class="float-none submit-button" id="myButton1">Hubungi CS kami di WA 0812 xxxx xxxx</button><script type="text/javascript">
    document.getElementById("myButton1").onclick = function () {   
fbq('track', 'Lead');
window.open('https://api.whatsapp.com/send?phone=62812xxxxxxxx&text=Hai%20kakak,%20saya%20tertarik%20untuk%20jadi%20agen%20produk%20kakak%20mohon%20info%20selanjutnya)');
    };
</script></h4>

Notes:
Before this can be tracked this event you need to install pixel code before </head> usually in the header file.
The code is something like this:
<!-- Facebook Pixel Code -->
<script>
  !function(f,b,e,v,n,t,s)
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
  n.queue=[];t=b.createElement(e);t.async=!0;
  t.src=v;s=b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t,s)}(window, document,'script',
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', '1xxxxxxxxxxxxxxx');
  fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
  src="https://www.facebook.com/tr?id=1xxxxxxxxxxxxxxx&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->

Good luck!
How To Add FB Pixel's Code Into A Button that open Whatsapp And Ready to Send A Message How To Add FB Pixel's Code Into A Button that open Whatsapp And Ready to Send A Message Reviewed by Yunar W on October 09, 2018 Rating: 5

No comments:

Powered by Blogger.