Reputation: 515
Added facebook pixel like they showed here here Now getting an error:
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.
Anyone knows what that means and how to solve this error ?
Upvotes: 37
Views: 62905
Reputation: 2966
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!)."
Upvotes: 4
Reputation: 1323
Before looking into hacking any code, it's worth checking the new trackSingle
call:
fbq('trackSingle', 'pixel-id1', 'PageView');
fbq('trackSingle', 'pixel-id2', 'Purchase');
It allows to use in one script, multiple fbq
functions with different scopes ('PageView','Purchase'), if the scope is instead the same for both pixels (for example 'PageView'), then you might just use the call like this:
fbq('init', 'pixel-id1');
fbq('init', 'pixel-id2');
fbq('track', 'PageView');
Upvotes: 0
Reputation: 43
You should simply check if fbq
is undefined before calling init
.
if (typeof fbq === 'undefined') {
fbq('init', 'your-pixel-ID');
}
Please note: don't wrap the full script with this if
statement!
Upvotes: 2
Reputation: 1145
I found the solution on this page actually.
Its because everytime you send an event the code is initialized with the same pixel id. Actually initialization should happen only once."
This fix works. You can verify that by using the Facebook Pixel Helper as an extension in 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}}');
}
Upvotes: 39
Reputation: 83
I had the same issue, and changing the facebook pixel initialization tag on GTM to "once per page" did the trick.
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.
Upvotes: 3
Reputation: 4103
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 init
your pixel ID are coming from.
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 and in a GTM container, which would cause this error.
If you're having trouble finding the two init
calls, one of the easiest ways to look for specific JavaScript code on a site is to use Chrome Developer Tools. Press F12 to open the tools, press Ctrl+Shift+F to open the search panel, then type fbq
or whatever you are looking for. It will go through the sources it has loaded for the site and look for that code.
Upvotes: 1
Reputation: 1
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
Upvotes: -1
Reputation: 883
This error generally means fbq('init', <pixel_id>)
is getting called more than once with the same pixel id.
Upvotes: 23