diff --git a/CHANGELOG.md b/CHANGELOG.md
index 56015d0..2aae3e6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [3.9.9] - 22 October 2024
+### Fixed
+- Add new order state to `order_states_for_purchase_event` default
+- New setting `googletagmanager2/settings/serverside_enabled`
+- Only custom order states for `purchase` when Server-Side Tracking is enabled
+
## [3.9.8] - 12 September 2024
### Fixed
- Fix Uncaught TypeError: products.forEach is not a function #246 @nahall
diff --git a/Config/Config.php b/Config/Config.php
index c6c20b0..01c81bb 100644
--- a/Config/Config.php
+++ b/Config/Config.php
@@ -56,20 +56,6 @@ public function isEnabled(): bool
return true;
}
- /**
- *
- * Get the Google tag manager url. Defaults to googletagmanager.com. when field is filled return that url.
- *
- * @return string
- */
- public function getGoogleTagmanagerUrl(): string
- {
- return $this->getModuleConfigValue(
- 'serverside_gtm_url',
- 'https://www.googletagmanager.com'
- );
- }
-
/**
* Check whether the module is in debugging mode
*
@@ -207,8 +193,38 @@ public function getProductListValueOnCategory(): string
return (string)$this->getModuleConfigValue('product_list_value_on_category');
}
+ public function hasServerSideTracking(): bool
+ {
+ return (bool)$this->getModuleConfigValue(
+ 'serverside_enabled',
+ 0
+ );
+ }
+
+ /**
+ *
+ * Get the Google tag manager url. Defaults to googletagmanager.com. when field is filled return that url.
+ *
+ * @return string
+ */
+ public function getGoogleTagmanagerUrl(): string
+ {
+ if (false === $this->hasServerSideTracking()) {
+ return '';
+ }
+
+ return $this->getModuleConfigValue(
+ 'serverside_gtm_url',
+ 'https://www.googletagmanager.com'
+ );
+ }
+
public function getOrderStatesForPurchaseEvent(): array
{
+ if (false === $this->hasServerSideTracking()) {
+ return [];
+ }
+
return explode(',', (string)$this->getModuleConfigValue('order_states_for_purchase_event'));
}
diff --git a/DataLayer/Event/Purchase.php b/DataLayer/Event/Purchase.php
index 21428d8..7a66a60 100644
--- a/DataLayer/Event/Purchase.php
+++ b/DataLayer/Event/Purchase.php
@@ -41,7 +41,7 @@ public function get(): array
return [];
}
- if (false === in_array($order->getState(), $this->getOrderStates())) {
+ if ($this->config->hasServerSideTracking() && false === in_array($order->getState(), $this->getOrderStates())) {
return [];
}
diff --git a/FAQ.md b/FAQ.md
index 1c2197e..e63831c 100644
--- a/FAQ.md
+++ b/FAQ.md
@@ -3,6 +3,11 @@ Yes, this extension ships with native JavaScript code that works with Hyvä. Add
Currently, Luma-based checkouts work without an issue, but for using the React-based checkout or the MageWire-based checkout, more work is needed.
+# This extension is not generating any `purchase` event
+First of all, make sure to upgrade to the latest version of this extension, before reporting any issue.
+
+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.
+
# Does this extension work under PHP 8.2?
Yes, version 3 does. Version 2 is no longer maintained, but you could use the following composer patch with `vaimo/composer-patches`:
```bash
diff --git a/composer.json b/composer.json
index ecba737..0a33891 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "yireo/magento2-googletagmanager2",
- "version": "3.9.8",
+ "version": "3.9.9",
"license": "OSL-3.0",
"type": "magento2-module",
"homepage": "https://www.yireo.com/software/magento-extensions/googletagmanager2",
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 4adae4b..9dd0309 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -33,12 +33,6 @@
1
-
-
- When a value is present in this field, data will send to this url instead of https://www.googletagmanager.com.
- Default output: https://gtm-test123.uc.r.appspot.com. Create a cname in the dns records for a name like marketing.shopname.com
- Keep in mind; enter a full url (with https://). ]]>
- Magento\Config\Model\Config\Source\Yesno
@@ -114,12 +108,27 @@
Generate the view_cart event only when expanding the minicart
-
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ 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.
+
+
+
+ When a value is present in this field, data will send to this url instead of https://www.googletagmanager.com.
+ Default output: https://gtm-test123.uc.r.appspot.com. Create a cname in the dns records for a name like marketing.shopname.com
+ Keep in mind; enter a full url (with https://). ]]>
+
+ 1
+
+
+ Yireo\GoogleTagManager2\Config\Source\OrderStateOptions
- Order states at which to trigger the purchase event
+ 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.1
+ 1
diff --git a/etc/config.xml b/etc/config.xml
index f9d0b2d..9616292 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -14,6 +14,8 @@
everywhere0product_first_category
+ 0
+ new,payment_review,pending_payment,holded,processing,complete