Skip to content

Commit 0e5c24a

Browse files
committed
Refactoring & Fixes
1 parent 907a8cf commit 0e5c24a

File tree

7 files changed

+62
-18
lines changed

7 files changed

+62
-18
lines changed

Block/Adminhtml/System/Config/Form/InfoMeasurementProtocol.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class InfoMeasurementProtocol extends InfoPlan
1212
{
13-
1413
/**
1514
* @return string
1615
*/
@@ -34,4 +33,32 @@ protected function getText(): string
3433
{
3534
return 'GA4 Measurement Protocol option is available in <strong>Extra</strong> plan only.';
3635
}
36+
37+
/**
38+
* Return info block html
39+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
40+
* @return string
41+
*/
42+
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
43+
{
44+
$html = parent::render($element);
45+
46+
$html .= '<div id="ga4mp-disabled" style="display:none; padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;">';
47+
$html .= 'GA4 Measurement Protocol is not available while <a href="#mfgoogletagmanager_server_container-head">GTM Server Container</a> is enabled.';
48+
$html .= '</div>';
49+
50+
$html .= '<script>
51+
require(["jquery", "Magento_Ui/js/modal/alert", "domReady!"], function($, alert){
52+
setInterval(function(){
53+
if (parseInt($("#mfgoogletagmanager_server_container_enabled").val())) {
54+
$("#ga4mp-disabled").show();
55+
} else {
56+
$("#ga4mp-disabled").hide();
57+
}
58+
}, 1000);
59+
});
60+
</script>';
61+
62+
return $html;
63+
}
3764
}

Controller/LastOrder/DataLayer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magefan\GoogleTagManager\Controller\LastOrder;
810

911
use Magento\Framework\App\Action\Context;

Model/Transaction/Log.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function isTransactionUnique($order, string $requester): bool
123123
*/
124124
private function getOrder($order): Order
125125
{
126-
if (is_object()) {
126+
if (is_object($order)) {
127127
if (!($order instanceof Order)) {
128128
throw new \Exception('Object is not instance of OrderInterface.');
129129
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"email": "[email protected]"
1010
}
1111
],
12-
"version": "2.4.2",
12+
"version": "2.5.0",
1313
"require": {
14-
"magefan/module-community" : ">=2.1.17"
14+
"magefan/module-community" : ">=2.1.18"
1515
},
1616
"autoload": {
1717
"files": [

etc/adminhtml/system.xml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ height=&quot;0&quot; width=&quot;0&quot; style=&quot;display:none;visibility:hid
202202
</field>
203203
<group id="measurement_protocol" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
204204
<label>Measurement Protocol /GA4 Server Side Tracking (GTM Extra)</label>
205-
<depends>
206-
<field id="mfgoogletagmanager/server_container/enabled">0</field>
207-
</depends>
208205
<attribute type="expanded">1</attribute>
209206

210207
<field id="info" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
@@ -218,10 +215,12 @@ height=&quot;0&quot; width=&quot;0&quot; style=&quot;display:none;visibility:hid
218215
The <a href="https://developers.google.com/analytics/devguides/collection/protocol/ga4" target="_blank" rel="nofollow noopener" title="Measurement Protocol (Google Analytics 4)">Google Analytics Measurement Protocol</a> enables server-side GA4 tracking.
219216
]]>
220217
</comment>
218+
<depends>
219+
<field id="mfgoogletagmanager/server_container/enabled">0</field>
220+
</depends>
221221
</field>
222222
<field id="api_secret" translate="label comment" type='obscure' sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
223223
<label>API Secret</label>
224-
<!-- <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>-->
225224
<comment><![CDATA[
226225
Required. An API Secret that is generated through the Google Analytics UI.<br/>
227226
@@ -232,15 +231,7 @@ To create a new secret, navigate in the
232231
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
233232
<depends>
234233
<field id="measurement_enabled">1</field>
235-
</depends>
236-
</field>
237-
<field id="headless_storefront" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
238-
<label>Headless Storefront</label>
239-
<comment><![CDATA[ Please enable this option if you have a PWA storefront.]]>
240-
</comment>
241-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
242-
<depends>
243-
<field id="measurement_enabled">1</field>
234+
<field id="mfgoogletagmanager/server_container/enabled">0</field>
244235
</depends>
245236
</field>
246237
</group>
@@ -321,6 +312,24 @@ To create a new secret, navigate in the
321312
</field>
322313
</group>
323314
</group>
315+
<group id="server_side_tracking" translate="label" type="text" sortOrder="55" showInDefault="1" showInWebsite="1" showInStore="1">
316+
<label>Server Side Tracking (GTM Extra)</label>
317+
<field id="headless_storefront" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
318+
<label>Headless Storefront</label>
319+
<comment><![CDATA[ Please select "Yes" if you have a PWA storefront.]]>
320+
</comment>
321+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
322+
</field>
323+
<field id="track_missing_purchase_events_only" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
324+
<label>Track Missing Purchase Events Only</label>
325+
<comment><![CDATA[ Please select "Yes" if you would like to use GA4 Measurement Protocol or GTM Server Container to track missing purchase events only.]]>
326+
</comment>
327+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
328+
<depends>
329+
<field id="headless_storefront">0</field>
330+
</depends>
331+
</field>
332+
</group>
324333
<group id="attributes" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
325334
<label>Product Attributes Mapping</label>
326335
<field id="product" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">

etc/config.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<measurement_protocol>
3636
<measurement_enabled/>
3737
<api_secret backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
38-
<headless_storefront/>
38+
3939
</measurement_protocol>
4040
</analytics>
4141
<ads>
@@ -53,6 +53,10 @@
5353
<conversion_label/>
5454
</remarketing>
5555
</ads>
56+
<server_side_tracking>
57+
<headless_storefront>0</headless_storefront>
58+
<track_missing_purchase_events_only>1</track_missing_purchase_events_only>
59+
</server_side_tracking>
5660
<attributes>
5761
<product>sku</product>
5862
<brand/>

registration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
55
*/
66

7+
declare(strict_types=1);
8+
79
use Magento\Framework\Component\ComponentRegistrar;
810

911
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magefan_GoogleTagManager', __DIR__);

0 commit comments

Comments
 (0)