-
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Google Tag Manager injection, compatible with Analy…
…tics 4 and enhanced ecommerce data (#3356)
- Loading branch information
Showing
7 changed files
with
146 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* OpenMage | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available at https://opensource.org/license/osl-3-0-php | ||
* | ||
* @category Mage | ||
* @package Mage_GoogleAnalytics | ||
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com) | ||
* @copyright Copyright (c) 2022 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* GoogleTagManager Page Block | ||
* | ||
* @category Mage | ||
* @package Mage_GoogleAnalytics | ||
*/ | ||
class Mage_GoogleAnalytics_Block_Gtm extends Mage_Core_Block_Template | ||
{ | ||
/** | ||
* @return bool | ||
*/ | ||
protected function _isAvailable() | ||
{ | ||
return Mage::helper('googleanalytics')->isGoogleTagManagerAvailable(); | ||
} | ||
|
||
/** | ||
* Render GA tracking scripts | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
if (!$this->_isAvailable()) { | ||
return ''; | ||
} | ||
return parent::_toHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/design/frontend/base/default/template/googleanalytics/gtm.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* OpenMage | ||
* | ||
* This source file is subject to the Academic Free License (AFL 3.0) | ||
* that is bundled with this package in the file LICENSE_AFL.txt. | ||
* It is also available at https://opensource.org/license/afl-3-0-php | ||
* | ||
* @category design | ||
* @package base_default | ||
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com) | ||
* @copyright Copyright (c) 2021 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
*/ | ||
?> | ||
<?php | ||
/** @var Mage_GoogleAnalytics_Block_Gtm $this */ | ||
$_helper = $this->helper('googleanalytics'); | ||
?> | ||
<?php if (!$this->helper('core/cookie')->isUserNotAllowSaveCookie()): ?> | ||
<?php if ($_helper->isUseGoogleTagManager()): ?> | ||
<?php $_gtmAccountId = $_helper->getGoogleTagManagerContainerId() ?> | ||
<!-- BEGIN GOOGLE TAG MANAGER CODE --> | ||
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | ||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | ||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= | ||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | ||
})(window,document,'script','dataLayer','<?= $_gtmAccountId ?>');</script> | ||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<?= $_gtmAccountId ?>" | ||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | ||
<!-- END GOOGLE TAG MANAGER CODE --> | ||
<?php endif ?> | ||
<?php endif ?> |