Detecting visits when inserting via API in reverse chronological order

Thanks for your help and ideas on this one.

My non-profit organization has well over a billion page views recorded in a database, and we’d like to insert those hits into Piwik via the API. We are using PHP and the PiwikTracker.php class, which is working great.

The problem I’ve noticed is that as we insert the hits (in reverse chronological order), the visits are not being detected. I’m assuming that’s because when a page view is inserted, Piwik looks in the past (window_look_back_for_visitor) time frame to match-up the page view with an existing visit.

However, since we are inserting in reverse chronological order, it doesn’t find the visit that exists in the near future.

Is there any way to resolve this, or are we doing something wrong? I would think that a page view insert should be looking in the future for visits as well for those situations when hits have to be inserted in the past.

You must import all hits in chronological order, not the other way. This is required for accurate tracking.