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 ? Commented Oct 24, 2020 at 11:28
  • No, I want to send order coupon to GA. so overriding this file. Commented Oct 24, 2020 at 16:49

1 Answer 1

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. Commented Oct 24, 2020 at 16:58
  • can you please clear the cache and check Commented Oct 26, 2020 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. Commented Oct 26, 2020 at 7:25
  • argument is wrong you pass in parent constructor, thats the issue Commented Oct 26, 2020 at 8:55

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.