javascript 如何设置 Facebook 像素“提交按钮”跟踪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33808385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set up facebook pixel "submit button" tracking
提问by uberMoon
I have a working facebook pixel that is tracking the audience on my website.
我有一个正在运行的 Facebook 像素,用于跟踪我网站上的受众。
<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
好的,所以这工作正常。现在我的问题是,如何设置此代码,所以我会跟踪
- website audience (this is already working)
- 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.
我还需要在 facebook 面板(https://business.facebook.com/ads/manager/pixel/facebook_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.
就我的研究而言,您必须在上述像素代码中的某处插入fbq('track', 'Lead'),但我仍然不知道如何将其链接到提交按钮以及如何获取所有这些数据到我的 facebook 开发面板。
Thank you for all your answers, Luka.
谢谢你的所有回答,卢卡。
回答by Laura P
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>