<?php if (!empty($p_data['facebook']) && !empty($p_data['facebook']['pixel_id']) && 
           (!empty($p_data['facebook'][$page_type .'_' .'page_load']) || !empty($p_data['facebook'][$page_type .'_' .'click']))) {
    
        //custom condition for loading pixel with channel id
        $channel_filter = array('121552'=>'476');
        if(array_key_exists($pubid, $channel_filter) && isset($channel) && $channel != $channel_filter[$pubid]) {
            return ;
        }

        $pixel_id = $p_data['facebook']['pixel_id'];
        $fb_standard_events = ['AddPaymentInfo','AddToCart','AddToWishlist','CompleteRegistration','Contact','CustomizeProduct',
        'Donate','FindLocation','InitiateCheckout','Lead','Purchase','Schedule','Search','StartTrial','SubmitApplication','Subscribe',
        'ViewContentStandard event code','AddPaymentInfo','AddToCart','AddToWishlist','CompleteRegistration','Contact','CustomizeProduct',
        'Donate','FindLocation','InitiateCheckout','Lead','Purchase','Schedule','Search','StartTrial','SubmitApplication','Subscribe','ViewContent'];        
    ?>
<!-- Meta Pixel Code -->
<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',
    'https://connect.facebook.net/en_US/fbevents.js');
    fbq('init', '<?php echo $pixel_id; ?>');
    fbq('track', "PageView");
    
    <?php if (!empty($p_data['facebook'][$page_type . '_' . 'page_load'])) {
            foreach ($p_data['facebook'][$page_type . '_' . 'page_load'] as $event_name) {
                if($event_name != 'PageView'){
                    if(in_array($event_name, $fb_standard_events, true)){
    ?>

    fbq('trackSingle', '<?= $pixel_id; ?>', '<?= $event_name; ?>');
        <?php       }else{ ?>   
    
    fbq('trackSingleCustom', '<?= $pixel_id; ?>', '<?= $event_name; ?>');    
    <?php           }
                }
            }
        } ?>

    var el = document.getElementById("track_click");
    el.addEventListener('click', function() {            
    <?php if (!empty($p_data['facebook'][$page_type . '_' . 'click'])) {
            foreach ($p_data['facebook'][$page_type . '_' . 'click'] as $event_name) {
                    if(in_array($event_name, $fb_standard_events, true)){
    ?>        
        fbq('trackSingle', '<?= $pixel_id; ?>', '<?= $event_name; ?>');                 
        <?php   }else{ ?>                    
        fbq('trackSingleCustom', '<?= $pixel_id; ?>', '<?= $event_name; ?>');    
    <?php       }
            }
        } ?>
    });
</script>
<noscript>
    <img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=<?= $pixel_id; ?>&ev=PageView&noscript=1" />
</noscript>

    <!-- End Meta Pixel Code -->
<?php } ?>