@@ -82,6 +82,7 @@ public function getPageName()
82
82
* @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#set
83
83
* @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#gaObjectMethods
84
84
* @deprecated 100.2.0 please use getPageTrackingData method
85
+ * @see getPageTrackingData method
85
86
*/
86
87
public function getPageTrackingCode ($ accountId )
87
88
{
@@ -103,6 +104,7 @@ public function getPageTrackingCode($accountId)
103
104
*
104
105
* @return string|void
105
106
* @deprecated 100.2.0 please use getOrdersTrackingData method
107
+ * @see getOrdersTrackingData method
106
108
*/
107
109
public function getOrdersTrackingCode ()
108
110
{
@@ -120,33 +122,35 @@ public function getOrdersTrackingCode()
120
122
foreach ($ collection as $ order ) {
121
123
$ result [] = "ga('set', 'currencyCode', ' " . $ order ->getOrderCurrencyCode () . "'); " ;
122
124
foreach ($ order ->getAllVisibleItems () as $ item ) {
125
+ $ quantity = $ item ->getQtyOrdered () * 1 ;
126
+ $ format = fmod ($ quantity , 1 ) !== 0.00 ? '%.2f ' : '%d ' ;
123
127
$ result [] = sprintf (
124
128
"ga('ec:addProduct', {
125
129
'id': '%s',
126
130
'name': '%s',
127
- 'price': '%s' ,
128
- 'quantity': %s
131
+ 'price': %.2f ,
132
+ 'quantity': $ format
129
133
}); " ,
130
134
$ this ->escapeJsQuote ($ item ->getSku ()),
131
135
$ this ->escapeJsQuote ($ item ->getName ()),
132
- $ item ->getPrice (),
133
- $ item -> getQtyOrdered ()
136
+ ( float ) $ item ->getPrice (),
137
+ $ quantity
134
138
);
135
139
}
136
140
137
141
$ result [] = sprintf (
138
142
"ga('ec:setAction', 'purchase', {
139
143
'id': '%s',
140
144
'affiliation': '%s',
141
- 'revenue': '%s' ,
142
- 'tax': '%s' ,
143
- 'shipping': '%s'
145
+ 'revenue': %.2f ,
146
+ 'tax': %.2f ,
147
+ 'shipping': %.2f
144
148
}); " ,
145
149
$ order ->getIncrementId (),
146
150
$ 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 (),
150
154
);
151
155
152
156
$ result [] = "ga('send', 'pageview'); " ;
@@ -232,19 +236,20 @@ public function getOrdersTrackingData()
232
236
233
237
foreach ($ collection as $ order ) {
234
238
foreach ($ order ->getAllVisibleItems () as $ item ) {
239
+ $ quantity = $ item ->getQtyOrdered () * 1 ;
235
240
$ result ['products ' ][] = [
236
241
'id ' => $ this ->escapeJsQuote ($ item ->getSku ()),
237
242
'name ' => $ this ->escapeJsQuote ($ item ->getName ()),
238
- 'price ' => $ item ->getPrice (),
239
- 'quantity ' => $ item -> getQtyOrdered () ,
243
+ 'price ' => ( float ) $ item ->getPrice (),
244
+ 'quantity ' => $ quantity ,
240
245
];
241
246
}
242
247
$ result ['orders ' ][] = [
243
248
'id ' => $ order ->getIncrementId (),
244
249
'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 (),
248
253
];
249
254
$ result ['currency ' ] = $ order ->getOrderCurrencyCode ();
250
255
}
0 commit comments