Purchase pixel didn't fire when the order was paid

kevin2017

Member
Hi dev team,

On testing my site, there was no purchase events fired after the orders were completed.

I saw the code and it should have fired. However, it didn't. I think this could't called the correct pages for event.

davinci/libs/fb_pixel.php

PHP:
<?php
/**
 * Author: Vitaly Kukin
 * Date: 03.10.2016
 * Time: 9:34
 */

function dav_fb_pixel() {

    global $wp, $adsBasket;



    if( is_singular('product') ) {

        global $post;

        ?>

        fbq(
            'track',
            'ViewContent',
            {
                content_ids: [<?php echo $post->ID ?>],
                content_name: '<?php echo addslashes($post->post_title) ?>',
                content_type: 'product',
                value: <?php echo $post->salePrice ?>,
                currency: '<?php echo ADS_CUR ?>'
            }
        );

        function loadJQuery(){

            var waitForLoad = function () {
                if (typeof jQuery != "undefined") {
                    jQuery(function($){

                        $('body').on( 'cart:add cart:shipping', function ( e ) {

                            var obj = e.cart,
                                total = obj.cur_salePrice.match(/-?\d+\.\d+/);

                            fbq('track', 'AddToCart', {
                                content_ids: [<?php echo $post->ID ?>],
                                content_type: 'product',
                                value: total[0],
                                currency: '<?php echo ADS_CUR ?>'
                            });

                        });
                    });
                }
                else {
                    window.setTimeout(waitForLoad, 500);
                }
            };
            window.setTimeout(waitForLoad, 500);
        }

        window.onload = loadJQuery;
        
        <?php
    }

    elseif(
        isset( $wp->query_vars[ "pagename" ] ) &&
        $wp->query_vars[ "pagename" ] == 'thankyou' &&
        isset($_GET['h']) && ! empty($_GET['h'])
    ) {

        $pay = new \Gate\Payment();

        $data = $pay->findOne( $_GET['h'] );

        if( $data && $data->status == 'paid') {
            
            $orders = $pay->get_orders( $data->id );
            
            $ids = array();
            
            if( $orders ) foreach( $orders as $order ){
                $ids[] = $order->productId;
            }
            
            ?>
            fbq(
                'track',
                'Purchase',
                {
                    content_ids: [<?php echo implode(',', $ids) ?>],
                    content_type: 'product',
                    value: <?php echo $data->amount_clean ?>,
                    currency: '<?php echo $data->currency_code ?>'
                }
            );
            <?php
        }
    }
}
add_action('dav_fb_pixel', 'dav_fb_pixel');
 

kevin2017

Member
Do you have a filter excluding the admin from results? If so, did you do the test logged out as admin?
I tested as the guest and got the same result. I'm sure the logic of this code has problem. I can't call the event


PHP:
 elseif(
        isset( $wp->query_vars[ "pagename" ] ) &&
        $wp->query_vars[ "pagename" ] == 'thankyou' &&
        isset($_GET['h']) && ! empty($_GET['h'])
    ) {

        $pay = new \Gate\Payment();

        $data = $pay->findOne( $_GET['h'] );

        if( $data && $data->status == 'paid') {
            
            $orders = $pay->get_orders( $data->id );
            
            $ids = array();
            
            if( $orders ) foreach( $orders as $order ){
                $ids[] = $order->productId;
            }
            
            ?>
            fbq(
                'track',
                'Purchase',
                {
                    content_ids: [<?php echo implode(',', $ids) ?>],
                    content_type: 'product',
                    value: <?php echo $data->amount_clean ?>,
                    currency: '<?php echo $data->currency_code ?>'
                }
            );
            <?php
        }
    }
 

Direct Webstore

Well-Known Member
Don't know. I use Woo and Pixel Caffeine which does filter out the admin. You can also use Pixel Caffeine with the Original plugin/Davinci if you want to try an alternative. Just delete your Pixel code from the Original Plugins settings. Same with the Original plugin's SEO options, you can leave them blank and use Yoast.
 

kevin2017

Member
Don't know. I use Woo and Pixel Caffeine which does filter out the admin. You can also use Pixel Caffeine with the Original plugin/Davinci if you want to try an alternative. Just delete your Pixel code from the Original Plugins settings. Same with the Original plugin's SEO options, you can leave them blank and use Yoast.

Pixel Caffeine didn't work with Divaci. I tested it. :(
 

kevin2017

Member
It did for me when I used it last year ... things have changed I guess :)
Thank you. This is one of the most important thing Alidropship team should take care of. But I haven't seen it fixed for a long time. I don't know what they want. They seem not to care about customers' opinions.
 

Direct Webstore

Well-Known Member
Thank you. This is one of the most important thing Alidropship team should take care of. But I haven't seen it fixed for a long time. I don't know what they want. They seem not to care about customers' opinions.
Have you written to support about it? They don't monitor everything here.
 
Top