Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trackOrder function doesn't track ecommerce events #456

Open
miletliyusuf opened this issue Aug 13, 2024 · 5 comments
Open

trackOrder function doesn't track ecommerce events #456

miletliyusuf opened this issue Aug 13, 2024 · 5 comments

Comments

@miletliyusuf
Copy link

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 ?

@brototyp
Copy link
Member

brototyp commented Sep 5, 2024

Hi @miletliyusuf, thanks for the report. This is very interesting. I noticed that we did not have an implementation for ecommerce tracking in the example application.
I added an example implementation; unfortunately, I cannot reproduce your issue. Do you mind having a look here so see if I misunderstood you? Can you give me an example to reproduce your issue?

@miletliyusuf
Copy link
Author

Hi @brototyp, thanks for the answer. I think the example here won't work because of the reason that I've mentioned above.

To demonstrate better:
Below API documentation clearly says that you must set idgoal value to 0 if you want to track orders.

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.

In trackOrder function on iOS framework, creates an Event object with default idgoal value nil which doesn't match API needs. And you can not set it from the trackOrder function itself because it's not provided. Even if you trigger the request by the iOS framework (as much as I can see)it's not tracked on API side.

Please let me know if you need more guidance in order to understand the issue ✌️

@brototyp
Copy link
Member

Hi @miletliyusuf, that's the thing. The example does work. I did execute the example code and this is what I see server side:

Bildschirmfoto 2024-09-23 um 21 04 20

Would you expect something else?

@miletliyusuf
Copy link
Author

Maybe the problem was on our side that we were trying to trackOrder with empty items array and thought it didn't work because of this idGoal value when we see on API doc. We don't have order item in our business scope to use with this function. Do you think can it be the reason ?

matomoTracker.trackOrder(id: "\(someID)", items: [], revenue: Float(revenue))

@brototyp
Copy link
Member

Hey @miletliyusuf, I just tried out the same thing, tracking an order without items, and I was able to reproduce you issue. It looks like the server doesn't accept orders if they don't have at least one item in it.

@mattab Can you confirm this? Is there anything possible to do, other than adding a placeholder item?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants