cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2.2.0 Community Edition Google Analytics Transaction Tracking issue.

SOLVED

Re: Magento2.2.0 Community Edition Google Analytics Transaction Tracking issue.

@maratheprash

Great, let me know if this will be helpful or if you need any other help.

Manish Mittal
https://www.manishmittal.com/

Re: Magento2.2.0 Community Edition Google Analytics Transaction Tracking issue.

@Manish Mittal
Hey Manish,

Thanks for your help and sorry for late reply.
This solution works properly for me only when I added this line in google analytics block. -
Block Name-
Magento\GoogleAnalytics\Block\Ga.php

 $result['currency'] = $order->getOrderCurrencyCode();

This line was missing in my block. when I added it then it works. Hence final code for this function looks like as follows. 

 /**
     * Return information about order and items for GA tracking.
     *
     * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#checkout-options
     * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-transactions
     * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#transaction
     *
     * @return array
     * @since 100.2.0
     */
    public function getOrdersTrackingData()
    {
        $result = [];
        $orderIds = $this->getOrderIds();
        if (empty($orderIds) || !is_array($orderIds)) {
            return $result;
        }

        $collection = $this->_salesOrderCollection->create();
        $collection->addFieldToFilter('entity_id', ['in' => $orderIds]);

        foreach ($collection as $order) {
            foreach ($order->getAllVisibleItems() as $item) {
                $result['products'][] = [
                    'id' => $this->escapeJs($item->getSku()),
                    'name' =>  $this->escapeJs($item->getName()),
                    'price' => $item->getBasePrice(),
                    'quantity' => $item->getQtyOrdered(),
                ];
            }
            $result['orders'][] = [
                'id' =>  $order->getIncrementId(),
                'affiliation' => $this->escapeJs($this->_storeManager->getStore()->getFrontendName()),
                'revenue' => $order->getBaseGrandTotal(),
                'tax' => $order->getBaseTaxAmount(),
                'shipping' => $order->getBaseShippingAmount(),
            ];
        }
        $result['currency'] = $order->getOrderCurrencyCode();
        return $result;
    }