34 private $cookieHelper;
46 \
Magento\GoogleAnalytics\Helper\Data $googleAnalyticsData,
48 \
Magento\Cookie\Helper\Cookie $cookieHelper =
null 50 $this->_googleAnalyticsData = $googleAnalyticsData;
51 $this->_salesOrderCollection = $salesOrderCollection;
53 parent::__construct($context,
$data);
64 return $this->_scopeConfig->getValue(
$path, \
Magento\Store\Model\ScopeInterface::SCOPE_STORE);
90 if ($this->_googleAnalyticsData->isAnonymizedIpActive()) {
91 $anonymizeIp =
"\nga('set', 'anonymizeIp', true);";
94 return "\nga('create', '" . $this->
escapeHtmlAttr($accountId,
false)
95 .
"', 'auto');{$anonymizeIp}\nga('send', 'pageview'{$this->getOptPageUrl()});\n";
115 $collection = $this->_salesOrderCollection->create();
119 $result[] =
"ga('require', 'ec', 'ec.js');";
122 $result[] =
"ga('set', 'currencyCode', '" .
$order->getOrderCurrencyCode() .
"');";
125 "ga('ec:addProduct', { 134 $item->getQtyOrdered()
139 "ga('ec:setAction', 'purchase', { 147 $this->
escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
150 $order->getShippingAmount()
153 $result[] =
"ga('send', 'pageview');";
165 if (!$this->_googleAnalyticsData->isGoogleAnalyticsAvailable()) {
169 return parent::_toHtml();
180 return $this->cookieHelper->isCookieRestrictionModeEnabled();
191 return $this->_storeManager->getWebsite()->getId();
207 'optPageUrl' => $this->getOptPageUrl(),
208 'isAnonymizedIpActive' => $this->_googleAnalyticsData->isAnonymizedIpActive(),
231 $collection = $this->_salesOrderCollection->create();
239 'price' =>
$item->getPrice(),
240 'quantity' =>
$item->getQtyOrdered(),
244 'id' => $order->getIncrementId(),
245 'affiliation' => $this->
escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
246 'revenue' =>
$order->getGrandTotal(),
247 'tax' =>
$order->getTaxAmount(),
248 'shipping' =>
$order->getShippingAmount(),
260 private function getOptPageUrl()
264 if ($pageName && substr($pageName, 0, 1) ==
'/' && strlen($pageName) > 1) {
265 $optPageURL =
", '" . $this->
escapeHtmlAttr($pageName,
false) .
"'";
getPageTrackingData($accountId)
escapeJsQuote($data, $quote='\'')
isCookieRestrictionModeEnabled()
getPageTrackingCode($accountId)
escapeHtmlAttr($string, $escapeSingleQuote=true)
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollection, \Magento\GoogleAnalytics\Helper\Data $googleAnalyticsData, array $data=[], \Magento\Cookie\Helper\Cookie $cookieHelper=null)