Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Pixel activated 2 times

I'm trying to put the Facebook Pixel on my website but i have this message on Chrome's Pixel Helper addon.

I have only pasted the js code they gave to me.

One more strange thing is that on the local website the addon says everything is good, but once only that's not the same and I don't understand why because I did'nt change any code.

Thank's for helping

like image 340
nocalis Avatar asked Feb 03 '16 09:02

nocalis


1 Answers

I found it was because of an angularjs redirection I had on the root of my site. I put a condition in facebook pixel code to check with the url if I needed to load the pixel or not.

EDIT :

Here is the script in my index.html. I look for '!#' in url, because the pixel was loading 2 times, once without '!#' and one with.

<script>
    // original 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', 'xXxXxXxXxXxXxXxx');
    // I check the url to see if there is the '#!' in it, if there is I don't load the pixel 
    var add = window.location.toString();
    if (add.indexOf("/#!/") != -1) {
        fbq('track', "PageView");
    }
</script>

Hope it can help you.

like image 180
nocalis Avatar answered Sep 30 '22 03:09

nocalis