关于FB像素的手动添加方式,很多兄弟以为只是单纯堆代码就可以了,实际上在动态加载的场景中,需要再页面渲染前将基础代码先渲染出来,否则会有可能出现一些事件像素代码加载不成功的情况,下面把代码发出来供大家参考
<!DOCTYPE html>
<html>
<head>
<title>Pixel Demo</title>
</head>
<body>
<button onclick="viewContent()">查看内容</button>
<button onclick="search()">搜索</button>
<button onclick="addToWishlist()">加入心愿单</button>
<button onclick="addToCart()">加入购物车</button>
<button onclick="initiateCheckout()">发起结账</button>
<button onclick="purchase()">购买</button>
<button onclick="completeRegistration()">完成注册</button>
</body>
<!-- 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', '817068068737662');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=817068068737662&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
<script type="text/javascript">
function viewContent(){
fbq('track', 'ViewContent');
}
function search(){
fbq('track', 'Search');
}
function addToWishlist(){
fbq('track', 'AddToWishlist');
}
function addToCart(){
fbq('track', 'AddToCart');
}
function initiateCheckout(){
fbq('track', 'InitiateCheckout');
}
function purchase(){
fbq('track', 'Purchase');
}
function completeRegistration(){
fbq('track', 'CompleteRegistration');
}
</script>
</html>