Disable with the #if (replaced "Debug version" with the function? It didn't seem to do anything. Thx. – Beachphool Apr 07 '19 at 22:06

  • You've marked this C#, but C# is a language, not a web UI framework. Are you using ASP.NET MVC? ASP.NET Web Forms? UWP? – Heretic Monkey Apr 07 '19 at 22:06
  • Sorry.. This is ASP.NET MVC – Beachphool Apr 07 '19 at 22:08
  • Also, you should theoretically be able to configure the tool (Facebook Pixel) to filter out calls from localhost for debugging purposes. – Heretic Monkey Apr 07 '19 at 22:08
  • Heretic Monkey - I don't have control over the FB Pixel stuff, so I don't know if they have done that or not. I'll send a message to them tomorrow to double-check. Thanks. – Beachphool Apr 07 '19 at 22:12
  • Thanks EdSF! I was able to figure out how to do it from that link. – Beachphool Apr 08 '19 at 00:45
  • 1 Answers1

    0

    (Thanks EdSF and everyone) The setting I was looking for was: this.Context.IsDebuggingEnabled

    <!-- Facebook Pixel Code -->
    <script>
    @if (!this.Context.IsDebuggingEnabled)
        {
            <text>
                !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', '<PixelID>');
                fbq('track', 'PageView');
            </text>
        }
    </script>
    <noscript>
    @if (!this.Context.IsDebuggingEnabled)
        {
            <text>
                <img height="1" width="1" style="display:none"
                    src="https://www.facebook.com/tr?id=<PixelID>&ev=PageView&noscript=1"/>
            </text>
        }
    </noscript>
    <!-- End Facebook Pixel Code -->
    

    On localhost, I get: <!-- Facebook Pixel Code --> <script> </script> <noscript> </noscript> <!-- End Facebook Pixel Code -->

    And on the server the functions are where they are supposed to be.

    Beachphool
    • 11
    • 3