@@ -219,57 +219,15 @@ def track_page_view(self, page_url, page_title=None, referrer=None, context=None
219219 pb .add_json (context , self .config ["encode_base64" ], "cx" , "co" )
220220 return self .track (pb )
221221
222- @contract
223- def track_ecommerce_transaction (self , order_id , tr_total_value ,
224- tr_affiliation = None , tr_tax_value = None , tr_shipping = None ,
225- tr_city = None , tr_state = None , tr_country = None , tr_currency = None ,
226- context = None ,
227- tstamp = None , tid = None ):
228- """
229- :param order_id: ID of the eCommerce transaction
230- :type order_id: non_empty_string
231- :param tr_total_value: Total transaction value
232- :type tr_total_value: int | float
233- :param tr_affiliation: Transaction affiliation
234- :type tr_affiliation: string_or_none
235- :param tr_tax_value: Transaction tax value
236- :type tr_tax_value: int | float | None
237- :param tr_shipping: Delivery cost charged
238- :type tr_shipping: int | float | None
239- :param tr_city: Delivery address city
240- :type tr_city: string_or_none
241- :param tr_state: Delivery address state
242- :type tr_state: string_or_none
243- :param tr_country: Delivery address country
244- :type tr_country: string_or_none
245- :param tr_currency: The currency the price is expressed in
246- :type tr_currency: string_or_none
247- :param context: Custom context for the event
248- :type context: dict(str:*) | None
249- :rtype: tuple(bool, int | str)
250- """
251- pb = payload .Payload (tstamp )
252- pb .add ("e" , "tr" )
253- pb .add ("tr_id" , order_id )
254- pb .add ("tr_af" , tr_affiliation )
255- pb .add ("tr_tt" , tr_total_value )
256- pb .add ("tr_tx" , tr_tax_value )
257- pb .add ("tr_sh" , tr_shipping )
258- pb .add ("tr_ci" , tr_city )
259- pb .add ("tr_st" , tr_state )
260- pb .add ("tr_co" , tr_country )
261- pb .add ("tr_cu" , tr_currency )
262- pb .add ("evn" , DEFAULT_VENDOR )
263- pb .add ("tid" , tid )
264- pb .add_json (context , self .config ["encode_base64" ], "cx" , "co" )
265- return self .track (pb )
266-
267222 @contract
268223 def track_ecommerce_transaction_item (self , ti_id , ti_sku , ti_price , ti_quantity ,
269224 ti_name = None , ti_category = None , ti_currency = None ,
270225 context = None ,
271226 tstamp = None , tid = None ):
272227 """
228+ This is an internal method called by track_ecommerce_transaction.
229+ It is not for public use.
230+
273231 :param ti_id: Order ID
274232 :type ti_id: non_empty_string
275233 :param ti_sku: Item SKU
@@ -301,12 +259,32 @@ def track_ecommerce_transaction_item(self, ti_id, ti_sku, ti_price, ti_quantity,
301259 pb .add ("tid" , tid )
302260 pb .add_json (context , self .config ["encode_base64" ], "cx" , "co" )
303261 return self .track (pb )
304-
262+
305263 @contract
306- def track_transaction (self , transaction , items , context = None , tstamp = None ):
264+ def track_ecommerce_transaction (self , order_id , tr_total_value ,
265+ tr_affiliation = None , tr_tax_value = None , tr_shipping = None ,
266+ tr_city = None , tr_state = None , tr_country = None , tr_currency = None ,
267+ items = None ,
268+ context = None , tstamp = None ):
307269 """
308- :param transaction The transaction event
309- :type transaction dict(str:*)
270+ :param order_id: ID of the eCommerce transaction
271+ :type order_id: non_empty_string
272+ :param tr_total_value: Total transaction value
273+ :type tr_total_value: int | float
274+ :param tr_affiliation: Transaction affiliation
275+ :type tr_affiliation: string_or_none
276+ :param tr_tax_value: Transaction tax value
277+ :type tr_tax_value: int | float | None
278+ :param tr_shipping: Delivery cost charged
279+ :type tr_shipping: int | float | None
280+ :param tr_city: Delivery address city
281+ :type tr_city: string_or_none
282+ :param tr_state: Delivery address state
283+ :type tr_state: string_or_none
284+ :param tr_country: Delivery address country
285+ :type tr_country: string_or_none
286+ :param tr_currency: The currency the price is expressed in
287+ :type tr_currency: string_or_none
310288 :param items: The items in the transaction
311289 :type items: list(dict(str:*))
312290 :param context: Custom context for the event
@@ -315,26 +293,40 @@ def track_transaction(self, transaction, items, context=None, tstamp=None):
315293 """
316294 if tstamp is None :
317295 tstamp = time .time ()
296+ if tstamp and isinstance (tstamp , (int , float )):
297+ tstamp = int (tstamp * 1000 )
318298
319299 tid = payload .Payload .set_transaction_id ()
320300
321- transaction ["tstamp" ] = tstamp
322- transaction ["tid" ] = tid
323- transaction_result = self .track_ecommerce_transaction (** transaction )
301+ pb = payload .Payload (tstamp )
302+ pb .add ("e" , "tr" )
303+ pb .add ("tr_id" , order_id )
304+ pb .add ("tr_tt" , tr_total_value )
305+ pb .add ("tr_af" , tr_affiliation )
306+ pb .add ("tr_tx" , tr_tax_value )
307+ pb .add ("tr_sh" , tr_shipping )
308+ pb .add ("tr_ci" , tr_city )
309+ pb .add ("tr_st" , tr_state )
310+ pb .add ("tr_co" , tr_country )
311+ pb .add ("tr_cu" , tr_currency )
312+ pb .add ("evn" , DEFAULT_VENDOR )
313+ pb .add ("tid" , tid )
314+ pb .add ("dtm" , tstamp )
315+ pb .add_json (context , self .config ["encode_base64" ], "cx" , "co" )
316+
317+ transaction_result = self .track (pb )
324318
325319 item_results = []
326320
327- if "tr_currency" in transaction :
328- for item in items :
329- item ["ti_currency" ] = transaction ["tr_currency" ]
330-
331321 for item in items :
332- item ["tstamp" ] = tstamp
322+ item ["tstamp" ] = str ( tstamp )
333323 item ["tid" ] = tid
324+ item ["ti_id" ] = order_id
325+ item ["ti_currency" ] = tr_currency
334326 item_results .append (self .track_ecommerce_transaction_item (** item ))
335-
327+
336328 return {"transaction_result" : transaction_result , "item_results" : item_results }
337-
329+
338330 @contract
339331 def track_screen_view (self , name , id_ = None , context = None , tstamp = None ):
340332 """
0 commit comments