Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up facebook pixel "submit button" tracking

I have a working facebook pixel that is tracking the audience on my website.

<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','//connect.facebook.net/en_US/fbevents.js');


fbq('init', 'myID');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=myID&ev=PageView&noscript=1"
/></noscript>

Ok, so this is working fine. Now my question is, how to set up this code, so i'll track

  1. website audience (this is already working)
  2. clicks on submit button

I would also need help with creating custom pixel in facebook panel (https://business.facebook.com/ads/manager/pixel/facebook_pixel/), because i really dont know which event to choose, and where to get code for that custom pixel.

As far as i got with my research, you have to insert fbq('track', 'Lead') somewhere in above pixel code, but i still have no idea, how to link that to submit button and how to get all this data to my facebook development panel.

Thank you for all your answers, Luka.

like image 364
uberMoon Avatar asked Nov 19 '15 15:11

uberMoon


1 Answers

You can do that by adding an event within the button. As you already have your base code set up and working, you just need to add the standard event code:

<button onClick="fbq('track', 'Purchase');">Button Text</button>

If you prefer, you can create a function that triggers the event:

<script>
function onClick() {
  fbq('track', 'Purchase');
};
</script>

And then call it, to fire the event when clicking the button:

<button onClick="onClick()">Buy Now</button>
like image 177
Laura P Avatar answered Sep 21 '22 01:09

Laura P