Home / eCommerce / Meta Pixel – ViewContent Event
Duplicate Snippet

Embed Snippet on Your Site

Meta Pixel – ViewContent Event

Meta Pixel - ViewContent Event

Code Preview
php
<?php
// Track ViewContent event on product pages
add_action('wp_footer', 'voelgoed_meta_pixel_view_content');
function voelgoed_meta_pixel_view_content() {
    if (!function_exists('is_product')) return;
    
    if (is_product()) {
        global $product;
        if (!$product) return;
        ?>
        <script>
        fbq('track', 'ViewContent', {
            content_ids: ['<?php echo $product->get_id(); ?>'],
            content_type: 'product',
            content_name: '<?php echo esc_js($product->get_name()); ?>',
            value: <?php echo $product->get_price(); ?>,
            currency: 'ZAR'
        });
        </script>
        <?php
    }
}

Comments

Add a Comment