You might have been stuck in a situation where you need to track some events that need some Javascript or basic coding knowledge. So today, I want to tell you how we can track "Button Clicks" with Facebook Pixel code.
Scenario - I have a submission form on my website's home page & whenever someone fills up that form & click on the "Submit" button, the URL is not changing. But I want to track the number of submissions I got or how many users clicked on that "Submit" button as I don't have access to Website's backend.
How we can do that?
First of all, we need to make sure that we have a basic pixel code installed on the homepage. It looks something like this:
If it is already installed, then we need to put a simple piece of code on the button click. Here is the 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', '246611512878205'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=246611512878205&ev=PageView&noscript=1" /></noscript>
<button onClick="fbq('track', 'Purchase');">Button Text</button>Just change the button text with your button's text & then you will be all good!
5 Comments
Hi, I've put the button tracker code to my site but it says,"Parsing error: Unexpected token <" to the first '<'. What to do now? Please help!
ReplyDeleteCan you send me the screenshot of the code?
DeleteI read this blog and its helpful!
ReplyDeleteAlgo Trading
Great article this worked for my site thanks this helped a lot!
ReplyDeleteHello i just try it with an unbounce landing page, i want to track clicks on my buttons, but it doesnt work
ReplyDelete