File tree Expand file tree Collapse file tree 7 files changed +49
-13
lines changed
Expand file tree Collapse file tree 7 files changed +49
-13
lines changed Original file line number Diff line number Diff line change @@ -46,8 +46,8 @@ class Config
4646 /**
4747 * Events config
4848 */
49- public const XML_PATH_EVENTS_PURCHASE_TAX_ENABLED = 'mfgoogletagmanager/events/purchase /tax_enabled ' ;
50- public const XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED = 'mfgoogletagmanager/events/purchase /shipping_enabled ' ;
49+ public const XML_PATH_EVENTS_PURCHASE_TAX_ENABLED = 'mfgoogletagmanager/events/price_tracking /tax_enabled ' ;
50+ public const XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED = 'mfgoogletagmanager/events/price_tracking /shipping_enabled ' ;
5151
5252 /**
5353 * Customer data protection regulation config
@@ -187,7 +187,7 @@ public function getMeasurementId(string $storeId = null): string
187187 * @param string|null $storeId
188188 * @return bool
189189 */
190- public function isPurchaseTaxEnabled (string $ storeId = null ): bool
190+ public function isTrackTaxEnabled (string $ storeId = null ): bool
191191 {
192192 return (bool )$ this ->getConfig (self ::XML_PATH_EVENTS_PURCHASE_TAX_ENABLED , $ storeId );
193193 }
@@ -196,7 +196,7 @@ public function isPurchaseTaxEnabled(string $storeId = null): bool
196196 * @param string|null $storeId
197197 * @return bool
198198 */
199- public function isPurchaseShippingEnabled (string $ storeId = null ): bool
199+ public function isTrackShippingEnabled (string $ storeId = null ): bool
200200 {
201201 return (bool )$ this ->getConfig (self ::XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED , $ storeId );
202202 }
Original file line number Diff line number Diff line change @@ -56,10 +56,23 @@ public function get(Quote $quote): array
5656 'event ' => 'begin_checkout ' ,
5757 'ecommerce ' => [
5858 'currency ' => $ this ->getCurrentCurrencyCode (),
59- 'value ' => $ this ->formatPrice (( float ) $ quote-> getGrandTotal () ),
59+ 'value ' => $ this ->getOrderValue ( $ quote ),
6060 'coupon ' => $ quote ->getCouponCode () ?: '' ,
6161 'items ' => $ items
6262 ]
6363 ]);
6464 }
65+ protected function getOrderValue ($ quote ): float
66+ {
67+ $ quoteValue = (float )$ quote ->getGrandTotal ();
68+ if (!$ this ->config ->isTrackTaxEnabled ()) {
69+ $ quoteValue -= (float )$ quote ->getShippingAddress ()->getTaxAmount ();
70+ }
71+
72+ if (!$ this ->config ->isTrackShippingEnabled ()) {
73+ $ quoteValue -= $ quote ->getShippingAddress ()->getShippingAmount ();
74+ }
75+
76+ return $ this ->formatPrice ($ quoteValue );
77+ }
6578}
Original file line number Diff line number Diff line change @@ -86,11 +86,11 @@ protected function getOrderValue($order): float
8686 {
8787 $ orderValue = (float )$ order ->getGrandTotal ();
8888
89- if (!$ this ->config ->isPurchaseTaxEnabled ()) {
89+ if (!$ this ->config ->isTrackTaxEnabled ()) {
9090 $ orderValue -= $ order ->getTaxAmount ();
9191 }
9292
93- if (!$ this ->config ->isPurchaseShippingEnabled ()) {
93+ if (!$ this ->config ->isTrackShippingEnabled ()) {
9494 $ orderValue -= $ order ->getShippingAmount ();
9595 }
9696
Original file line number Diff line number Diff line change @@ -58,12 +58,25 @@ public function get(Quote $quote): array
5858 'event ' => 'view_cart ' ,
5959 'ecommerce ' => [
6060 'currency ' => $ this ->getCurrentCurrencyCode (),
61- 'value ' => $ this ->formatPrice (( float ) $ quote-> getGrandTotal () ),
61+ 'value ' => $ this ->getOrderValue ( $ quote ),
6262 'items ' => $ items
6363 ],
6464 'items_count ' => count ($ items ),
6565 'items_qty ' => $ itemsQty ,
6666 'coupon_code ' => $ quote ->getCouponCode () ?: ''
6767 ]);
6868 }
69+ protected function getOrderValue ($ quote ): float
70+ {
71+ $ quoteValue = (float )$ quote ->getGrandTotal ();
72+ if (!$ this ->config ->isTrackTaxEnabled ()) {
73+ $ quoteValue -= (float )$ quote ->getShippingAddress ()->getTaxAmount ();
74+ }
75+
76+ if (!$ this ->config ->isTrackShippingEnabled ()) {
77+ $ quoteValue -= $ quote ->getShippingAddress ()->getShippingAmount ();
78+ }
79+
80+ return $ this ->formatPrice ($ quoteValue );
81+ }
6982}
Original file line number Diff line number Diff line change @@ -52,11 +52,21 @@ public function get(Product $product): array
5252 'event ' => 'view_item ' ,
5353 'ecommerce ' => [
5454 'currency ' => $ this ->getCurrentCurrencyCode (),
55- 'value ' => $ this ->getPrice ($ product ),
55+ 'value ' => $ this ->getOrderValue ($ product ),
5656 'items ' => [
5757 $ item
5858 ]
5959 ]
6060 ]);
6161 }
62+ protected function getOrderValue ($ product ): float
63+ {
64+ $ productValue = $ this ->getPrice ($ product );
65+
66+ if (!$ this ->config ->isTrackTaxEnabled ()) {
67+ $ productValue = $ product ->getPriceInfo ()->getPrice ('final_price ' )->getAmount ()->getValue ('tax ' );
68+ }
69+
70+ return $ this ->formatPrice ($ productValue );
71+ }
6272}
Original file line number Diff line number Diff line change @@ -348,8 +348,8 @@ To create a new secret, navigate in the
348348 </group >
349349 <group id =" events" translate =" label" type =" text" sortOrder =" 62" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
350350 <label >Events</label >
351- <group id =" purchase " translate =" label" type =" text" sortOrder =" 10" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
352- <label >Purchase </label >
351+ <group id =" price_tracking " translate =" label" type =" text" sortOrder =" 10" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
352+ <label >Price Tracking </label >
353353 <field id =" shipping_enabled" translate =" label comment" type =" select" sortOrder =" 10" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" canRestore =" 1" >
354354 <label >Include Shipping In Purchase Value</label >
355355 <comment >If enabled, shipping amount will be included into purchase value (the monetary value of the event).</comment >
Original file line number Diff line number Diff line change 6363 <categories />
6464 </attributes >
6565 <events >
66- <purchase >
66+ <price_tracking >
6767 <shipping_enabled >1</shipping_enabled >
6868 <tax_enabled >1</tax_enabled >
69- </purchase >
69+ </price_tracking >
7070 </events >
7171 <page_speed_optimization >
7272 <enabled >0</enabled >
You can’t perform that action at this time.
0 commit comments