Javascript 如何修复重复的 Facebook 像素 ID 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36313317/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:54:18  来源:igfitidea点击:

How to fix Duplicate Facebook pixel ID error?

javascriptfacebook-ads-apifacebook-pixel

提问by Eugene Monakov

Added facebook pixel like they showed here hereNow getting an error:

添加了 facebook 像素,就像他们在此处显示的那样 现在出现错误:

fbevents.js:9 Facebook Pixel Error: Duplicate Pixel ID: some-pixel-id

Cannot understand what causes this error. Even when I run the code from their example with removed pixel code from html in the console I get the same result.

无法理解导致此错误的原因。即使我在控制台中使用从 html 中删除的像素代码运行他们示例中的代码时,我也会得到相同的结果。

Anyone knows what that means and how to solve this error ?

任何人都知道这意味着什么以及如何解决此错误?

回答by Zdenek Hatak

I found the solution on thispage actually.

我实际上在页面上找到了解决方案。

Its because everytime you send an event the code is initialized with the same pixel id. Actually initialization should happen only once."

这是因为每次发送事件时,代码都会使用相同的像素 id 进行初始化。实际上初始化应该只发生一次。”

This fix works. You can verify that by using the Facebook Pixel Helper as an extension in Chrome.

此修复程序有效。您可以通过使用 Facebook Pixel Helper 作为 Chrome 中的扩展来验证这一点。

if(typeof fbq === 'undefined') {
    !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', '123123123213121');
    fbq('track', 'PageView');
    fbq('track', '{{fBPixelType}}');
  }
  else {
    fbq('track', '{{fBPixelType}}');
  }

回答by Craig Kochis

This error generally means fbq('init', <pixel_id>)is getting called more than once with the same pixel id.

此错误通常意味着fbq('init', <pixel_id>)使用相同的像素 id 被多次调用。

回答by rassom

Another answer found in the Google Forum: "You have to check whether your Facebook Pixel code is only initialised once per page (and not per event). Go to the tag where your FB Pixel code is and open the advanced settings. Tag firing options -> Once per page (not event!)."

在 Google 论坛中找到的另一个答案:“您必须检查您的 Facebook 像素代码是否每页(而不是每个事件)仅初始化一次。转到您的 FB 像素代码所在的标签并打开高级设置。标签触发选项-> 每页一次(不是事件!)。”

回答by jgggr

I had the same issue, and changing the facebook pixel initialization tag on GTM to "once per page" did the trick.

我遇到了同样的问题,将 GTM 上的 Facebook 像素初始化标签更改为“每页一次”就可以了。

I know someone already answered that, but since that are more than one solution provided and the "selected" answer seems, to me, more complicated than this answer I thought i would comment here so that other people with the same problem feel confident to try this simpler approach.

我知道有人已经回答了这个问题,但是由于提供的解决方案不止一个,而且“选定”的答案对我来说似乎比这个答案更复杂,我想我会在这里发表评论,以便其他有同样问题的人有信心尝试这种更简单的方法。

回答by John Washam

This error will only occur if you try to initialize a pixel ID more than once, so you need to check all of the JavaScript code loading on your site and find where the multiple calls to inityour pixel ID are coming from.

仅当您尝试多次初始化像素 ID 时才会发生此错误,因此您需要检查您网站上加载的所有 JavaScript 代码,并找出多次调用init您的像素 ​​ID 的来源。

Key area to check is to right-click on your site and click "View page source." Then check all referenced JavaScript files and any GTM containers you are referencing. I've heard of developers including the Facebook pixel code both in the <head>of the site andin a GTM container, which would cause this error.

要检查的关键区域是右键单击您的站点,然后单击“查看页面源代码”。然后检查所有引用的 JavaScript 文件和您引用的任何 GTM 容器。我听说开发人员<head>在网站GTM 容器中都包含 Facebook 像素代码,这会导致此错误。

If you're having trouble finding the two initcalls, one of the easiest ways to look for specific JavaScript code on a site is to use Chrome Developer Tools. Press F12to open the tools, press Ctrl+Shift+Fto open the search panel, then type fbqor whatever you are looking for. It will go through the sources it has loaded for the site and look for that code.

如果您在查找这两个init调用时遇到问题,在站点上查找特定 JavaScript 代码的最简单方法之一是使用 Chrome 开发人员工具。按F12打开工具,按Ctrl+ Shift+F打开搜索面板,然后键入fbq或您要查找的任何内容。它将遍历它为站点加载的源并查找该代码。

回答by Adam Fills

I was having the same issue in my shopify store but I researched and find out that Trackify fb pixel app is my option. I removed all previous pixels and events that I created in past (was experimenting) and install the app it helps creating multiple events and pixels

我在我的 shopify 商店中遇到了同样的问题,但我研究并发现 Trackify fb pixel 应用程序是我的选择。我删除了我过去创建的所有像素和事件(正在试验)并安装该应用程序,它有助于创建多个事件和像素