0

I am overriding Google analytics block file.

Here is my Vendor/Module/etc/di.xml

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\GoogleAnalytics\Block\Ga" type="Vendor\Module\Block\Ga" />
 </config>

Then Vendor\Module\Block\Ga.php

<?php
 namespace Vendor\Module\Block;
 use Magento\Framework\App\ObjectManager;
class Ga extends \Magento\GoogleAnalytics\Block\Ga
{

protected $_googleAnalyticsData = null;  
protected $_salesOrderCollection;   
private $cookieHelper = null;
protected $moduleHelper;

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollection,
    \Magento\GoogleAnalytics\Helper\Data $googleAnalyticsData,  
    \Magento\Cookie\Helper\Cookie $cookieHelper,
    \Vendor\Module\Helper\Data $moduleHelper,
    array $data = []
) {
    $this->moduleHelper= $moduleHelper;
    parent::__construct($context, $salesOrderCollection, $googleAnalyticsData, $cookieHelper, $data);       
}

public function getOrdersTrackingData()
{   
    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/ganatics.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info('--module ovrride--');
    $result = [];
    $orderIds = $this->getOrderIds();       
    if (empty($orderIds) || !is_array($orderIds)) {
        return $result;
    }
   }
 } 

upon using above code I am getting the below error during compilation.

Incompatible argument type: Required type: array. Actual type: \Magento\Cookie\Helper\Cookie; File:

Can anyone help me on this issue please, please explain what is wrong here. Thanks

2
  • Do you want to get order id at success page for GA ?
    – Pawan
    Oct 24 '20 at 11:28
  • No, I want to send order coupon to GA. so overriding this file.
    – Manjunath
    Oct 24 '20 at 16:49
1

mistack in the line

parent::__construct($context, $salesOrderCollection, $googleAnalyticsData, $cookieHelper, $data);  

replace this line with

parent::__construct($context, $salesOrderCollection, $googleAnalyticsData,$data, $cookieHelper); 
4
  • No still same issue.
    – Manjunath
    Oct 24 '20 at 16:58
  • can you please clear the cache and check Oct 26 '20 at 3:27
  • yes Thanks, its working. can you please explain me what's wrong in my code, i was sending $data parameter at last.
    – Manjunath
    Oct 26 '20 at 7:25
  • argument is wrong you pass in parent constructor, thats the issue Oct 26 '20 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.