matomo-sdk-ios
matomo-sdk-ios copied to clipboard
trackOrder function doesn't track ecommerce events
Hello 👋 ,
As described in the title, when you try to trigger event for ecommerce over trackOrder function it doesn't triggered (probably)because of below reason by the API description.
API: https://developer.matomo.org/api-reference/tracking-api#optional-ecommerce-info
you must set &idgoal=0 in the request to track an ecommerce interaction: cart update or an ecommerce order.
public func trackOrder(id: String, items: [OrderItem], revenue: Float, subTotal: Float? = nil, tax: Float? = nil, shippingCost: Float? = nil, discount: Float? = nil) {
let lastOrderDate = matomoUserDefaults.lastOrder
let event = Event(tracker: self, action: [], orderId: id, orderItems: items, orderRevenue: revenue, orderSubTotal: subTotal, orderTax: tax, orderShippingCost: shippingCost, orderDiscount: discount, orderLastDate: lastOrderDate, isCustomAction: false)
queue(event: event)
matomoUserDefaults.lastOrder = Date()
}
Above the trackOrder
function creates the Event but, by default, the goal id is nil and there is no way to set it by this function.
For the workaround: I've set custom Event for tracking ecommerce event something like below:
let eCommerceEvent = Event(tracker: matomoTracker, action: [], goalId: 0, orderId: "\(orderID)",
orderRevenue: revenue, orderLastDate: Date(), isCustomAction: false)
matomoTracker.track(eCommerceEvent)
I hope, the workaround is fine? or do you folks have any other suggestion ?