我们正在尝试使用Facebook的广告跟踪像素来跟踪广告。我们查看了Facebook的文档,这使我无法找到任何地方。
我需要知道如何在一个页面上触发多个Facebook像素,因为我们有多个广告在运行。
我取了它给我的每个像素的代码,并把它放在页面上,然后我们就有了一个购物车页面,在这个页面中我启动或添加了“购买”事件。但既然我有了剧本3次,它似乎就发射了3次。我想让它每像素发射一次。
到目前为止,这就是我所拥有的:
<!-- Facebook Pixel Code - Ad 1-->
<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', 'xxxxxxxxxxxxx12');
fbq('track', "PageView");
// Purchase
// Track purchases or checkout flow completions (ex. landing on "Thank You" or confirmation page)
fbq('track', 'Purchase', {value: '1.00', currency: 'USD'});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxxxxxx12&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
<!-- Facebook Pixel Code - Ad 2-->
<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', 'xxxxxxxxxxxxx34');
fbq('track', "PageView");
// Purchase
// Track purchases or checkout flow completions (ex. landing on "Thank You" or confirmation page)
fbq('track', 'Purchase', {value: '1.00', currency: 'USD'});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxxxxxx34&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
<!-- Facebook Pixel Code - Ad 2-->
<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', 'xxxxxxxxxxxxx56');
fbq('track', "PageView");
// Purchase
// Track purchases or checkout flow completions (ex. landing on "Thank You" or confirmation page)
fbq('track', 'Purchase', {value: '1.00', currency: 'USD'});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxxxxxx56&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
就这样做吗?或者我需要做一些不同的事情,以使购买事件不会被解雇4次。我正在使用插件的Chrome,以确保所有像素都启动,但我得到一个错误,他们是多次触发。
,我会这样做吗?
<!-- Facebook Pixel Code - ALL ADS-->
<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', 'xxxxxxxxxxxxx12');
fbq('init', 'xxxxxxxxxxxxx34');
fbq('init', 'xxxxxxxxxxxxx56');
fbq('track', "PageView");
// Purchase
// Track purchases or checkout flow completions (ex. landing on "Thank You" or confirmation page)
fbq('track', 'Purchase', {value: '1.00', currency: 'USD'});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxxxxxx12&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
发布于 2016-04-16 03:52:57
我遇到了同样的问题,在任何地方都找不到解决办法。我深入研究了代码,并找到了一种可以使用的方法,称为"addPixelId“。在我的测试中,您可以在"init“之后使用它,这将添加第二个ID,您跟踪的任何事件现在都将发送到两个ID。例如:
fbq('init', 'xxxxxxxxxxxxx12');
fbq('addPixelId', 'xxxxxxxxxxxxx34');
fbq('addPixelId', 'xxxxxxxxxxxxx56');
fbq('track', 'PageView');
唯一需要注意的另一件事是,您跟踪的任何事件都会被您定义的所有ID所跟踪。这对我来说很棒,没有任何问题。
发布于 2016-10-20 09:20:03
简单地放入一个JS文件,代码: //Facebook多像素
(function() {
var fbq = (function() {
function fbq()
{
if(arguments.length > 0) {
var action, pixel_id, type_track, content_obj;
if( typeof arguments[0] == "string") action = arguments[0];
if( typeof arguments[1] == "string") pixel_id = arguments[1];
if( typeof arguments[2] == "string") type_track = arguments[2];
if( typeof arguments[3] == "object") content_obj = arguments[3];
var params = [];
if(typeof action == "string" && action.replace(/\s+/gi, "") != "" &&
typeof pixel_id == "string" && pixel_id.replace(/\s+/gi, "") != "" &&
typeof type_track == "string" && type_track.replace(/\s+/gi, "")) {
params.push("id=" + encodeURIComponent(pixel_id));
switch(type_track) {
case "PageView":
case "ViewContent":
case "Search":
case "AddToCart":
case "InitiateCheckout":
case "AddPaymentInfo":
case "Lead":
case "CompleteRegistration":
case "Purchase":
case "AddToWishlist":
params.push("ev=" + encodeURIComponent(type_track));
break;
default:
return;
}
params.push("dl=" + encodeURIComponent(document.location.href));
params.push("rl=" + encodeURIComponent(document.referrer));
params.push("if=false");
params.push("ts=" + new Date().getTime());
if(typeof content_obj == "object") {
for(var u in content_obj) {
if(typeof content_obj[u] == "object" && content_obj[u] instanceof Array) {
if(content_obj[u].length > 0) {
for(var y=0; y<content_obj[u].length; y++) { content_obj[u][y] = (content_obj[u][y]+"").replace(/^\s+|\s+$/gi, "").replace(/\s+/gi," ").replace(/,/gi, "§"); }
params.push("cd[" + u + "]=" + encodeURIComponent(content_obj[u].join(",").replace(/^/gi, "[\"").replace(/$/gi, "\"]").replace(/,/gi, "\",\"").replace(/§/gi, "\,")));
}
}
else if(typeof content_obj[u] == "string")
params.push("cd[" + u + "]=" + encodeURIComponent(content_obj[u]));
}
}
params.push("v=" + encodeURIComponent("2.5.0"));
if(typeof window.jQuery == "function") {
var iframe_id = new Date().getTime();
jQuery("body").append("<img height='1' width='1' style='display:none;width:1px;height:1px;' id='fb_" + iframe_id + "' src='https://www.facebook.com/tr/?" + params.join("&") + "' />");
setTimeout(function() { jQuery("#fb_" + iframe_id).remove(); }, 1000);
}
}
}
}
return fbq;
});
window.fbq = new fbq();
})();
还有,用法示例:
fbq('track', "<PIXEL_ID>", "PageView");
fbq('track", "<PIXEL_ID>", "ViewContent", {
content_name: "name test",
content_category: "category test",
content_ids: ["test"],
content_type: "product",
value: 7.99,
currency: "GBP"
});
诸若此类。
发布于 2017-03-11 04:48:40
这是我推荐的基于Facebook源代码(基于https://developers.facebook.com/)的当前工作方法。多次使用"init“函数,那么简单.
<!-- 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', '158xxxxxxxxxx911');
fbq('init', '180xxxxxxxxxx762');
fbq('init', '125xxxxxxxxxx694');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=180xxxxxxxxxx762&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
https://stackoverflow.com/questions/35926833
复制相似问题