Conversion Tracking and Dynamic Remarketing Tag instructions for Magento 2.X

Improve your advertising effectiveness by setting up conversion tracking and dynamic remarketing tag on your Magento 2.X website

  1. You will first need to import the FeedOps Google Tag Manager container on your website.
  2. Once Google Tag Manager has been set up, provide the following scripts to your web developer so they can be added to your Magento 2.X store.
    The below script should be added to the "HOME" pages:

    <!-- FeedOps - Dynamic Remarketing - Version 1 START -->
    <script>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
    'event': 'DynamicRemarketing',
    'ecomm_pagetype': 'home',
    });
    </script>
    <!-- FeedOps - Dynamic Remarketing - Version 1 END -->
    The below script should be added to the "PRODUCT" page - (product.phtml): 

    <!-- FeedOps - Dynamic Remarketing - Version 1 START -->
    <?php $_product = $block->getProduct(); ?>
    <script>
    dataLayer.push({
    'event': 'DynamicRemarketing',
    'ecomm_pagetype': 'product',
    'ecomm_totalvalue': <?php echo $_product->getPrice() ?>,
    'currency': '#ADD_STORE_CURRENCY',
    'ecomm_prodid': [
    <?php echo $_product->getId() ?>
    ]
    });
    </script>
    <!-- FeedOps - Dynamic Remarketing - Version 1 END -->
    The below script should be added to "public_html/vendor/magento/module-checkout/Block/Onepage/Success.php"

    public function getRealOrderDetail() {
    return $this->_checkoutSession->getLastRealOrder();
    }
    The below script should be added to the "PURCHASE SUCCESSFUL" page - (success.phtml): 

    <!-- FeedOps - Dynamic Remarketing - Version 1 START -->
    <?php
        $order_id = $block->getRealOrderDetail()->getIncrementId();
        $total = $block->getRealOrderDetail()->getGrandTotal();
        $items = $block->getRealOrderDetail()->getAllVisibleItems();
        $email = $block->getRealOrderDetail()->getCustomerEmail();
        
        $product_ids = array();
        foreach($items as $item) {
            array_push($product_ids, $item->getProductId());
        }
    ?>

    <script type="text/javascript">
        dataLayer.push({
            'event': 'DynamicRemarketing',
            'user_email': <?php echo "\"$email\"" ?>,
            'ecomm_pagetype': 'purchase',
            'order_id': <?php echo "\"$order_id\"" ?>,
            'ecomm_totalvalue': <?php echo $total ?>,
            'currency': '#ADD_STORE_CURRENCY',
            'ecomm_prodid': <?php echo json_encode($product_ids) ?>
        });
    </script>
    <!-- FeedOps - Dynamic Remarketing - Version 1 END -->
    The below script should be added to the "PRODUCT" page > "ADD TO CART" event - (cart.phtml):

    <!-- FeedOps - Dynamic Remarketing - Version 1 START -->
    <script>
    function addToCartClick() {
    dataLayer.push({
    'event': 'DynamicRemarketing',
    'ecomm_pagetype': 'cart',
    'ecomm_totalvalue': <?php echo $_product->getPrice() ?>,
    'currency': '#ADD_STORE_CURRENCY',
    'ecomm_prodid': [
    <?php echo $_product->getId() ?>
    ]
    });
    }
    var form = document.getElementById(#ID OF ADD TO CART FORM);
    if(form.addEventListener){
    form.addEventListener("submit", addToCartClick, false);
    }else if(form.attachEvent){
    form.attachEvent('onsubmit', addToCartClick);
    }
    </script>
    <!-- FeedOps - Dynamic Remarketing - Version 1 END -->

If you need help adding the scripts to your Magento 2.X store, please contact us at sales@feedops.com

To verify that your Dynamic Remarketing and Conversion Tracking works, you can follow Test Dynamic Remarketing Tags & ConversionTracking Test Transaction guides.