forked from magepal/magento2-google-tag-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGtmCode.php
executable file
·93 lines (82 loc) · 1.97 KB
/
GtmCode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
namespace MagePal\GoogleTagManager\Block;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use MagePal\GoogleTagManager\Helper\Data as GtmHelper;
class GtmCode extends Template
{
/**
* @var GtmHelper
*/
protected $_gtmHelper = null;
/**
* @param Context $context
* @param GtmHelper $gtmHelper
* @param array $data
*/
public function __construct(
Context $context,
GtmHelper $gtmHelper,
array $data = []
) {
$this->_gtmHelper = $gtmHelper;
parent::__construct($context, $data);
}
/**
* Get Account Id
*
* @return string
*/
public function getAccountId()
{
return $this->_gtmHelper->getAccountId();
}
/**
* @return string
*/
public function getDataLayerName()
{
return $this->_gtmHelper->getDataLayerName();
}
/**
* @return string
*/
public function getEmbeddedAccountId()
{
return $this->_gtmHelper->isMultiContainerEnabled() ?
$this->getAccountId() . $this->_gtmHelper->getMultiContainerCode() : $this->getAccountId();
}
/**
* Render tag manager JS
*
* @return string
*/
protected function _toHtml()
{
if (!$this->_gtmHelper->isEnabled()) {
return '';
}
return parent::_toHtml();
}
/**
* @param null $store_id
* @return bool
*/
public function isAdvancedSettingsEnabled($store_id = null)
{
return $this->_gtmHelper->isAdvancedSettingsEnabled($store_id);
}
/**
* @param null $store_id
* @return string
*/
public function getAdvancedSettingsIframeCode($store_id = null)
{
return $this->_gtmHelper->getAdvancedSettingsIframeCode($store_id);
}
}