Duplicate rows in Analytics Orders export
-
I spent a couple days trying to figure out why an export of orders placed over the course of several months was giving a small number of duplicate entries. We’re talking like less than 20 in an export of 12,000.
I had the same export from a few months ago and was able to diff the two reports to really lock in on what was missing and what was duplicated. At a few points throughout, I’d see an order appear twice, while an order with a close ID a couple lines removed wasn’t present at all.
A little bit of backstory: we regularly import dozens to hundreds of orders once a month from a third-party processor (don’t ask) and all of them are set with the same date and time, usually because they get backdated a couple hours or so, sometimes a couple days. The point is, they have the exact same timestamp.
Digging into the diffed reports I mentioned, I was really seeing the duplicate entries at points when the imported orders with the same date and time tended to align with the batch cutoff around 100.
Took that bit of info, and tried to find where the query is set up for the order exports. Found
woocommerce/src/Admin/API/Reports/Orders/Query.php
which gave me thewoocommerce_analytics_orders_query_args
filter. From there, I backtracked around a little bit to find out I could change theorderby
argument toorder_id
.Gave that a shot by hooking onto that filter for my site, and everything came out exactly as expected.
add_filter( 'woocommerce_analytics_orders_query_args', function( $query_args ) { $query_args['orderby'] = 'order_id'; return $query_args; } );
That might be a place to look with an issue like these ones (they’re closed so I can’t post a reply to ask):
- https://www.ads-software.com/support/topic/i-have-duplicate-data-in-my-woocommerce-analytics-report/
- https://www.ads-software.com/support/topic/duplicate-entries-in-goods-analytics-download/
My use case is such that I can use an export ordered by the ID numbers because I end up re-sorting elsewhere. I don’t know that most people would be in that boat though.
Realistically, I probably shouldn’t have dozens or hundreds of orders with the exact same timestamp. I realize that. This particular issue wasn’t on my mind when that was written. Going back, I’ll probably offset each imported order by a second so this wouldn’t happen.
Hopefully that can be of some help to someone else who came looking for a similar issue.
- The topic ‘Duplicate rows in Analytics Orders export’ is closed to new replies.