@@ -82,6 +82,7 @@ public function getPageName()
8282 * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#set
8383 * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#gaObjectMethods
8484 * @deprecated 100.2.0 please use getPageTrackingData method
85+ * @see getPageTrackingData method
8586 */
8687 public function getPageTrackingCode ($ accountId )
8788 {
@@ -103,6 +104,7 @@ public function getPageTrackingCode($accountId)
103104 *
104105 * @return string|void
105106 * @deprecated 100.2.0 please use getOrdersTrackingData method
107+ * @see getOrdersTrackingData method
106108 */
107109 public function getOrdersTrackingCode ()
108110 {
@@ -120,33 +122,35 @@ public function getOrdersTrackingCode()
120122 foreach ($ collection as $ order ) {
121123 $ result [] = "ga('set', 'currencyCode', ' " . $ order ->getOrderCurrencyCode () . "'); " ;
122124 foreach ($ order ->getAllVisibleItems () as $ item ) {
125+ $ quantity = $ item ->getQtyOrdered () * 1 ;
126+ $ format = fmod ($ quantity , 1 ) !== 0.00 ? '%.2f ' : '%d ' ;
123127 $ result [] = sprintf (
124128 "ga('ec:addProduct', {
125129 'id': '%s',
126130 'name': '%s',
127- 'price': '%s' ,
128- 'quantity': %s
131+ 'price': %.2f ,
132+ 'quantity': $ format
129133 }); " ,
130134 $ this ->escapeJsQuote ($ item ->getSku ()),
131135 $ this ->escapeJsQuote ($ item ->getName ()),
132- $ item ->getPrice (),
133- $ item -> getQtyOrdered ()
136+ ( float ) $ item ->getPrice (),
137+ $ quantity
134138 );
135139 }
136140
137141 $ result [] = sprintf (
138142 "ga('ec:setAction', 'purchase', {
139143 'id': '%s',
140144 'affiliation': '%s',
141- 'revenue': '%s' ,
142- 'tax': '%s' ,
143- 'shipping': '%s'
145+ 'revenue': %.2f ,
146+ 'tax': %.2f ,
147+ 'shipping': %.2f
144148 }); " ,
145149 $ order ->getIncrementId (),
146150 $ this ->escapeJsQuote ($ this ->_storeManager ->getStore ()->getFrontendName ()),
147- $ order ->getGrandTotal (),
148- $ order ->getTaxAmount (),
149- $ order ->getShippingAmount ()
151+ ( float ) $ order ->getGrandTotal (),
152+ ( float ) $ order ->getTaxAmount (),
153+ ( float ) $ order ->getShippingAmount (),
150154 );
151155
152156 $ result [] = "ga('send', 'pageview'); " ;
@@ -232,19 +236,20 @@ public function getOrdersTrackingData()
232236
233237 foreach ($ collection as $ order ) {
234238 foreach ($ order ->getAllVisibleItems () as $ item ) {
239+ $ quantity = $ item ->getQtyOrdered () * 1 ;
235240 $ result ['products ' ][] = [
236241 'id ' => $ this ->escapeJsQuote ($ item ->getSku ()),
237242 'name ' => $ this ->escapeJsQuote ($ item ->getName ()),
238- 'price ' => $ item ->getPrice (),
239- 'quantity ' => $ item -> getQtyOrdered () ,
243+ 'price ' => ( float ) $ item ->getPrice (),
244+ 'quantity ' => $ quantity ,
240245 ];
241246 }
242247 $ result ['orders ' ][] = [
243248 'id ' => $ order ->getIncrementId (),
244249 'affiliation ' => $ this ->escapeJsQuote ($ this ->_storeManager ->getStore ()->getFrontendName ()),
245- 'revenue ' => $ order ->getGrandTotal (),
246- 'tax ' => $ order ->getTaxAmount (),
247- 'shipping ' => $ order ->getShippingAmount (),
250+ 'revenue ' => ( float ) $ order ->getGrandTotal (),
251+ 'tax ' => ( float ) $ order ->getTaxAmount (),
252+ 'shipping ' => ( float ) $ order ->getShippingAmount (),
248253 ];
249254 $ result ['currency ' ] = $ order ->getOrderCurrencyCode ();
250255 }
0 commit comments