Best place to put Facebook tracking pixel?

I'm trying an ad campaign, and want to track successful signups for a specific course. Where would the best place be to put a facebook tracking pixel for a successful course signup? In the Products/Store Settings/Order Complete page? Would that work?

  • Vaughan

    Hi Michelle,

    Hope you're well?

    I had to read up on what FB pixels are, but I don't think you'd be able to simply paste the code into the check out complete page unfortunately as that would not accept the javascript for it to work for security reasons.

    So ideally, you would most likely need to edit the template itself, or add it as a custom function.

    Can you adding the following to your theme functions.php

    function add_fb_pixel_to_mp() {
        $current_page = $_SERVER['REQUEST_URI'];
        if(strpos($current_page, 'shopping-cart/confirmation/')) {
            echo 'FB PIXEL CODE HERE';
        }
    }
    add_action('wp_head', 'add_fb_pixel_to_mp');

    then copy/paste your FB Pixel code where it says FB PIXEL CODe HERE

    All being well, it should now only inject the fb script on the mp confirmation page.

    Hope this helps

  • Michelle

    AAAAAUUGGGGGGHHH WHITE SCREEN OF DEATH!
    (It's a good thing I vaguely know what I'm doing.)
    I ssh'ed into the server and removed the offending code. Here's what the final code looked like:

    function add_fb_pixel_to_mp() {
        $current_page = $_SERVER['REQUEST_URI'];
        if(strpos($current_page, 'shopping-cart/confirmation/')) {
            echo '<!-- Facebook Conversion Code for Take Charge Complete Sale -->
    <script>(function() {
    var _fbq = window._fbq || (window._fbq = []);
    if (!_fbq.loaded) {
    var fbds = document.createElement('script');
    fbds.async = true;
    fbds.src = '//connect.facebook.net/en_US/fbds.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(fbds, s);
    _fbq.loaded = true;
    }
    })();
    window._fbq = window._fbq || [];
    window._fbq.push(['track', '6026814024994', {'value':'0.00','currency':'USD'}]);
    </script>
    <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6026814024994&cd[value]=0.00&cd[currency]=USD&noscript=1" /></noscript>';
        }
    }
    add_action('wp_head', 'add_fb_pixel_to_mp');

    And here's the error that got thrown:

    [17-Aug-2015 23:32:08 UTC] PHP Parse error: syntax error, unexpected '&', expecting ']' in /home/consciz7/public_html/courses/wp-content/plugins/coursepress/themes/coursepress/functions.php on line 444

    Ideas?

  • Vaughan

    hi,

    It's probably the single quotes. in the echo.

    Try this instead.

    function add_fb_pixel_to_mp() {
        $current_page = $_SERVER['REQUEST_URI'];
        if(strpos($current_page, 'shopping-cart/confirmation/')) {
            ?>
    <!-- Facebook Conversion Code for Take Charge Complete Sale -->
    <script>(function() {
    var _fbq = window._fbq || (window._fbq = []);
    if (!_fbq.loaded) {
    var fbds = document.createElement('script');
    fbds.async = true;
    fbds.src = '//connect.facebook.net/en_US/fbds.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(fbds, s);
    _fbq.loaded = true;
    }
    })();
    window._fbq = window._fbq || [];
    window._fbq.push(['track', '6026814024994', {'value':'0.00','currency':'USD'}]);
    </script>
    <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6026814024994&cd[value]=0.00&cd[currency]=USD&noscript=1" /></noscript>;
    
    <?php
        }
    }
    add_action('wp_head', 'add_fb_pixel_to_mp');

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.