Import ecommerce transactions

(Joe Workman) #1

I would like to ensure that all e-commerce transactions that happen actually get into Piwik so that I know that my reports are as accurate as possible. If a users has opted out of analytics, I would still like their transaction logged in the e-commerce reports. Is there an API that I can leverage that will let me add e-commerce transactions after the fact? I would also need to first see if the transaction existed first so that I don’t add duplicates.

(Joe Workman) #2

Anyone? Could I email someone at Piwik to help?

(Melissa Avery-Weir) #3

This is totally possible. I’ve written something to import sales from various sales portals, but I didn’t have visitor information with it, so each transaction was an individual visit. That meant no “time to conversion” type of analytics, no cart analysis, etc.

Is that what you’re looking for? I could share relevant portions of my code. I made it as an external python script that ran on a cron job, but it could be done as a plugin leveraging a scheduled task.

(Joe Workman) #4

Thank you so much! I fully understand that I will lose the cart analytics. The cart software that I use is currently working on adding Piwik integration. However, I would like to at least have some decent commerce reporting before that happens.

(Joe Workman) #5

Did you any sort of API to insert the data? Or did you simply insert it directly into the database?

(Melissa Avery-Weir) #6

I used the HTTP API. My code isn’t the most efficient – I was never importing many sales at once, so I let them send individually instead of using bulk tracking. (Plus, I ran into some issue with using bulk tracking, I think.)

I’ve put the majority of it in a gist: Sanitized piwik ecommerce importer · GitHub.

Essentially, the SalesDataProcessor reads in all the sales and queues up Piwik ecommerce requests, then tells the tracker to fire off the set. That code is for a CSV import, but it could be anything. (The real code I used had a set of five of those classes for the different services I connected to.)

Not sure if you’re a developer or not (or vehemently anti-Python :grin:), but let me know if you want a more detailed breakdown of what’s happening in the code.