Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Google Analytics3 and Universal Analytics #3347

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 7 additions & 208 deletions app/code/core/Mage/GoogleAnalytics/Block/Ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,6 @@
*/
class Mage_GoogleAnalytics_Block_Ga extends Mage_Core_Block_Template
{
/**
* @deprecated after 1.4.1.1
* @see self::_getOrdersTrackingCode()
* @return string
*/
public function getQuoteOrdersHtml()
{
return '';
}

/**
* @deprecated after 1.4.1.1
* self::_getOrdersTrackingCode()
* @return string
*/
public function getOrderHtml()
{
return '';
}

/**
* @deprecated after 1.4.1.1
* @see _toHtml()
* @return string
*/
public function getAccount()
{
return '';
}

/**
* Get a specific page name (may be customized via layout)
*
* @return string
* @deprecated
*/
public function getPageName()
{
return $this->_getData('page_name') ?? '';
}

/**
* Render regular page tracking javascript code
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
Expand All @@ -75,11 +34,9 @@ protected function _getPageTrackingCode($accountId)
$helper = $this->helper('googleanalytics');
if ($helper->isUseAnalytics4()) {
return $this->_getPageTrackingCodeAnalytics4($accountId);
} elseif ($helper->isUseUniversalAnalytics()) {
return $this->_getPageTrackingCodeUniversal($accountId);
} else {
return $this->_getPageTrackingCodeAnalytics($accountId);
}

return '';
}

/**
Expand Down Expand Up @@ -125,14 +82,11 @@ protected function _getPageTrackingCodeAnalytics4($accountId)
*
* @param string $accountId
* @return string
* @deprecated
*/
protected function _getPageTrackingCodeUniversal($accountId)
{
return "
ga('create', '{$this->jsQuoteEscape($accountId)}', 'auto');
" . $this->_getAnonymizationCode() . "
ga('send', 'pageview');
";
return '';
}

/**
Expand All @@ -143,19 +97,11 @@ protected function _getPageTrackingCodeUniversal($accountId)
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gaq.html
* @param string $accountId
* @return string
* @deprecated
*/
protected function _getPageTrackingCodeAnalytics($accountId)
{
$pageName = trim($this->getPageName());
$optPageURL = '';
if ($pageName && preg_match('/^\/.*/i', $pageName)) {
$optPageURL = ", '{$this->jsQuoteEscape($pageName)}'";
}
return "
_gaq.push(['_setAccount', '{$this->jsQuoteEscape($accountId)}']);
" . $this->_getAnonymizationCode() . "
_gaq.push(['_trackPageview'{$optPageURL}]);
";
return '';
}

/**
Expand All @@ -170,65 +116,9 @@ protected function _getOrdersTrackingCode()
$helper = $this->helper('googleanalytics');
if ($helper->isUseAnalytics4()) {
return $this->_getOrdersTrackingCodeAnalytics4();
} elseif ($helper->isUseUniversalAnalytics()) {
return $this->_getOrdersTrackingCodeUniversal();
}

return $this->_getOrdersTrackingCodeAnalytics();
}

/**
* Render information about specified orders and their items
*
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
protected function _getOrdersTrackingCodeUniversal()
{
$orderIds = $this->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
$collection = Mage::getResourceModel('sales/order_collection')
->addFieldToFilter('entity_id', ['in' => $orderIds]);
$result = [];
$result[] = "ga('require', 'ecommerce')";
foreach ($collection as $order) {
$result[] = sprintf(
"ga('ecommerce:addTransaction', {
'id': '%s',
'affiliation': '%s',
'revenue': '%s',
'tax': '%s',
'shipping': '%s'
});",
$order->getIncrementId(),
$this->jsQuoteEscape(Mage::app()->getStore()->getFrontendName()),
$order->getBaseGrandTotal(),
$order->getBaseTaxAmount(),
$order->getBaseShippingAmount()
);
foreach ($order->getAllVisibleItems() as $item) {
$result[] = sprintf(
"ga('ecommerce:addItem', {
'id': '%s',
'sku': '%s',
'name': '%s',
'category': '%s',
'price': '%s',
'quantity': '%s'
});",
$order->getIncrementId(),
$this->jsQuoteEscape($item->getSku()),
$this->jsQuoteEscape($item->getName()),
null, // there is no "category" defined for the order item
$item->getBasePrice(),
$item->getQtyOrdered()
);
}
$result[] = "ga('ecommerce:send');";
}
return implode("\n", $result);
return '';
}

/**
Expand Down Expand Up @@ -501,97 +391,6 @@ protected function _getOrdersTrackingCodeAnalytics4()
}

/**
* Render information about specified orders and their items
*
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
protected function _getOrdersTrackingCodeAnalytics()
{
$orderIds = $this->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
$collection = Mage::getResourceModel('sales/order_collection')
->addFieldToFilter('entity_id', ['in' => $orderIds]);
$result = [];
foreach ($collection as $order) {
if ($order->getIsVirtual()) {
$address = $order->getBillingAddress();
} else {
$address = $order->getShippingAddress();
}
$result[] = sprintf(
"_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']);",
$order->getIncrementId(),
$this->jsQuoteEscape(Mage::app()->getStore()->getFrontendName()),
$order->getBaseGrandTotal(),
$order->getBaseTaxAmount(),
$order->getBaseShippingAmount(),
$this->jsQuoteEscape(Mage::helper('core')->escapeHtml($address->getCity())),
$this->jsQuoteEscape(Mage::helper('core')->escapeHtml($address->getRegion())),
$this->jsQuoteEscape(Mage::helper('core')->escapeHtml($address->getCountry()))
);
foreach ($order->getAllVisibleItems() as $item) {
$result[] = sprintf(
"_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);",
$order->getIncrementId(),
$this->jsQuoteEscape($item->getSku()),
$this->jsQuoteEscape($item->getName()),
null, // there is no "category" defined for the order item
$item->getBasePrice(),
$item->getQtyOrdered()
);
}
$result[] = "_gaq.push(['_trackTrans']);";
}
return implode("\n", $result);
}

/**
* Render IP anonymization code for page tracking javascript code
*
* @return string
*/
protected function _getAnonymizationCode()
{
if (!Mage::helper('googleanalytics')->isIpAnonymizationEnabled()) {
return '';
}

/** @var Mage_GoogleAnalytics_Helper_Data $helper */
$helper = $this->helper('googleanalytics');
if ($helper->isUseUniversalAnalytics()) {
return $this->_getAnonymizationCodeUniversal();
}

return $this->_getAnonymizationCodeAnalytics();
}

/**
* Render IP anonymization code for page tracking javascript universal analytics code
*
* @return string
*/
protected function _getAnonymizationCodeUniversal()
{
return "ga('set', 'anonymizeIp', true);";
}

/**
* Render IP anonymization code for page tracking javascript google analytics code
*
* @return string
*/
protected function _getAnonymizationCodeAnalytics()
{
return "_gaq.push (['_gat._anonymizeIp']);";
}

/**
* Is ga available
*
* @return bool
*/
protected function _isAvailable()
Expand Down
17 changes: 4 additions & 13 deletions app/code/core/Mage/GoogleAnalytics/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Mage_GoogleAnalytics_Helper_Data extends Mage_Core_Helper_Abstract
public const XML_PATH_ACTIVE = 'google/analytics/active';
public const XML_PATH_TYPE = 'google/analytics/type';
public const XML_PATH_ACCOUNT = 'google/analytics/account';
public const XML_PATH_ANONYMIZATION = 'google/analytics/anonymization';
public const XML_PATH_DEBUG = 'google/analytics/debug';
public const XML_PATH_USERID = 'google/analytics/user_id';

Expand All @@ -37,17 +36,8 @@ class Mage_GoogleAnalytics_Helper_Data extends Mage_Core_Helper_Abstract
public const TYPE_ANALYTICS4 = 'analytics4';

/**
* @var string classic google analytics tracking code
* @deprecated
* @var string
*/
public const TYPE_ANALYTICS = 'analytics';

/**
* @var string google analytics universal tracking code
* @deprecated
*/
public const TYPE_UNIVERSAL = 'universal';

protected $_moduleName = 'Mage_GoogleAnalytics';

/**
Expand All @@ -67,10 +57,11 @@ public function isGoogleAnalyticsAvailable($store = null)
*
* @param null|string|bool|int|Mage_Core_Model_Store $store $store
* @return bool
* @deprecated
*/
public function isIpAnonymizationEnabled($store = null)
{
return Mage::getStoreConfigFlag(self::XML_PATH_ANONYMIZATION, $store);
return false;
}

/**
Expand All @@ -93,7 +84,7 @@ public function getAccountId($store = null)
*/
public function isUseUniversalAnalytics($store = null)
{
return Mage::getStoreConfig(self::XML_PATH_TYPE, $store) == self::TYPE_UNIVERSAL;
return false;
}

/**
Expand Down
12 changes: 0 additions & 12 deletions app/code/core/Mage/GoogleAnalytics/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@
*/
class Mage_GoogleAnalytics_Model_Observer
{
/**
* Create Google Analytics block for success page view
*
* @deprecated after 1.3.2.3 Use setGoogleAnalyticsOnOrderSuccessPageView() method instead
* @param Varien_Event_Observer $observer
*/
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function order_success_page_view($observer)
{
$this->setGoogleAnalyticsOnOrderSuccessPageView($observer);
}

/**
* Add order information into GA block to render on checkout success pages
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ public function toOptionArray()
[
'value' => Mage_GoogleAnalytics_Helper_Data::TYPE_ANALYTICS4,
'label' => Mage::helper('googleanalytics')->__('Google Analytics 4')
],
[
'value' => Mage_GoogleAnalytics_Helper_Data::TYPE_ANALYTICS,
'label' => Mage::helper('googleanalytics')->__('Google Analytics')
],
[
'value' => Mage_GoogleAnalytics_Helper_Data::TYPE_UNIVERSAL,
'label' => Mage::helper('googleanalytics')->__('Universal Analytics')
]
];
}
Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2925,16 +2925,6 @@ parameters:
count: 1
path: app/code/core/Mage/GiftMessage/controllers/IndexController.php

-
message: "#^Method Mage_GoogleAnalytics_Block_Ga\\:\\:_getOrdersTrackingCodeAnalytics\\(\\) should return string but empty return statement found\\.$#"
count: 1
path: app/code/core/Mage/GoogleAnalytics/Block/Ga.php

-
message: "#^Method Mage_GoogleAnalytics_Block_Ga\\:\\:_getOrdersTrackingCodeUniversal\\(\\) should return string but empty return statement found\\.$#"
count: 1
path: app/code/core/Mage/GoogleAnalytics/Block/Ga.php

-
message: "#^Return type \\(void\\) of method Mage_GoogleCheckout_Model_Payment\\:\\:authorize\\(\\) should be compatible with return type \\(\\$this\\(Mage_Payment_Model_Method_Abstract\\)\\) of method Mage_Payment_Model_Method_Abstract\\:\\:authorize\\(\\)$#"
count: 1
Expand Down