Skip to content

Commit 285ca71

Browse files
committed
Enable custom order states for purchase only when server-side tracking
1 parent ae359c1 commit 285ca71

File tree

7 files changed

+62
-24
lines changed

7 files changed

+62
-24
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [3.9.9] - 22 October 2024
10+
### Fixed
11+
- Add new order state to `order_states_for_purchase_event` default
12+
- New setting `googletagmanager2/settings/serverside_enabled`
13+
- Only custom order states for `purchase` when Server-Side Tracking is enabled
14+
915
## [3.9.8] - 12 September 2024
1016
### Fixed
1117
- Fix Uncaught TypeError: products.forEach is not a function #246 @nahall

Config/Config.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,6 @@ public function isEnabled(): bool
5656
return true;
5757
}
5858

59-
/**
60-
*
61-
* Get the Google tag manager url. Defaults to googletagmanager.com. when field is filled return that url.
62-
*
63-
* @return string
64-
*/
65-
public function getGoogleTagmanagerUrl(): string
66-
{
67-
return $this->getModuleConfigValue(
68-
'serverside_gtm_url',
69-
'https://www.googletagmanager.com'
70-
);
71-
}
72-
7359
/**
7460
* Check whether the module is in debugging mode
7561
*
@@ -207,8 +193,38 @@ public function getProductListValueOnCategory(): string
207193
return (string)$this->getModuleConfigValue('product_list_value_on_category');
208194
}
209195

196+
public function hasServerSideTracking(): bool
197+
{
198+
return (bool)$this->getModuleConfigValue(
199+
'serverside_enabled',
200+
0
201+
);
202+
}
203+
204+
/**
205+
*
206+
* Get the Google tag manager url. Defaults to googletagmanager.com. when field is filled return that url.
207+
*
208+
* @return string
209+
*/
210+
public function getGoogleTagmanagerUrl(): string
211+
{
212+
if (false === $this->hasServerSideTracking()) {
213+
return '';
214+
}
215+
216+
return $this->getModuleConfigValue(
217+
'serverside_gtm_url',
218+
'https://www.googletagmanager.com'
219+
);
220+
}
221+
210222
public function getOrderStatesForPurchaseEvent(): array
211223
{
224+
if (false === $this->hasServerSideTracking()) {
225+
return [];
226+
}
227+
212228
return explode(',', (string)$this->getModuleConfigValue('order_states_for_purchase_event'));
213229
}
214230

DataLayer/Event/Purchase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function get(): array
4141
return [];
4242
}
4343

44-
if (false === in_array($order->getState(), $this->getOrderStates())) {
44+
if ($this->config->hasServerSideTracking() && false === in_array($order->getState(), $this->getOrderStates())) {
4545
return [];
4646
}
4747

FAQ.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Yes, this extension ships with native JavaScript code that works with Hyvä. Add
33

44
Currently, Luma-based checkouts work without an issue, but for using the React-based checkout or the MageWire-based checkout, more work is needed.
55

6+
# This extension is not generating any `purchase` event
7+
First of all, make sure to upgrade to the latest version of this extension, before reporting any issue.
8+
9+
When making use of Server-Side Tracking, make sure to customize the setting **Orders states for purchase event** (`order_states_for_purchase_event`) and to manually trigger the `purchase` event where needed.
10+
611
# Does this extension work under PHP 8.2?
712
Yes, version 3 does. Version 2 is no longer maintained, but you could use the following composer patch with `vaimo/composer-patches`:
813
```bash

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yireo/magento2-googletagmanager2",
3-
"version": "3.9.8",
3+
"version": "3.9.9",
44
"license": "OSL-3.0",
55
"type": "magento2-module",
66
"homepage": "https://www.yireo.com/software/magento-extensions/googletagmanager2",

etc/adminhtml/system.xml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
<field id="enabled">1</field>
3434
</depends>
3535
</field>
36-
<field id="serverside_gtm_url" type="text" translate="label" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
37-
<label>Container URL</label>
38-
<comment><![CDATA[<span>When a value is present in this field, data will send to this url instead of https://www.googletagmanager.com.
39-
Default output: https://gtm-test123.uc.r.appspot.com. Create a cname in the dns records for a name like marketing.shopname.com</span><br/>
40-
<b>Keep in mind</b>; enter a full url (with https://). ]]></comment>
41-
</field>
4236
<field id="debug" type="select" translate="label" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
4337
<label>Debug</label>
4438
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
@@ -114,12 +108,27 @@
114108
</depends>
115109
<comment>Generate the view_cart event only when expanding the minicart</comment>
116110
</field>
117-
<field id="order_states_for_purchase_event" type="multiselect" translate="label" sortOrder="16" showInDefault="1" showInWebsite="1" showInStore="1">
111+
<field id="serverside_enabled" type="select" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
112+
<label>Server-Side Tracking</label>
113+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
114+
<comment>Only enable this, if you are using some kind of Server-Side Tracking extension already. Note that this extension does not enable Server-Side Tracking.</comment>
115+
</field>
116+
<field id="serverside_gtm_url" type="text" translate="label" sortOrder="31" showInDefault="1" showInWebsite="1" showInStore="1">
117+
<label>Container URL</label>
118+
<comment><![CDATA[<span>When a value is present in this field, data will send to this url instead of https://www.googletagmanager.com.
119+
Default output: https://gtm-test123.uc.r.appspot.com. Create a cname in the dns records for a name like marketing.shopname.com</span><br/>
120+
<b>Keep in mind</b>; enter a full url (with https://). ]]></comment>
121+
<depends>
122+
<field id="serverside_enabled">1</field>
123+
</depends>
124+
</field>
125+
<field id="order_states_for_purchase_event" type="multiselect" translate="label" sortOrder="32" showInDefault="1" showInWebsite="1" showInStore="1">
118126
<label>Orders states for purchase event</label>
119127
<source_model>Yireo\GoogleTagManager2\Config\Source\OrderStateOptions</source_model>
120-
<comment>Order states at which to trigger the purchase event</comment>
128+
<comment>Order states at which to trigger the purchase event. Note that this only makes sense when using Server-Side Tracking, because otherwise no purchase event will be triggered ever. When Server-Side Tracking is disabled in this extension, the default of this setting will be to trigger at any state.</comment>
121129
<depends>
122130
<field id="enabled">1</field>
131+
<field id="serverside_enabled">1</field>
123132
</depends>
124133
</field>
125134
</group>

etc/config.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<view_cart_occurances>everywhere</view_cart_occurances>
1515
<view_cart_on_mini_cart_expand_only>0</view_cart_on_mini_cart_expand_only>
1616
<product_list_value_on_category>product_first_category</product_list_value_on_category>
17+
<serverside_enabled>0</serverside_enabled>
18+
<serverside_gtm_url/>
1719
<order_states_for_purchase_event>new,payment_review,pending_payment,holded,processing,complete</order_states_for_purchase_event>
1820
</settings>
1921
</googletagmanager2>

0 commit comments

Comments
 (0)