[SOLVED] Importing historical data via the API doesn't show on Piwik


I’m running a custom script to import data in a very specific way. Historical visits are logged properly, however I can’t get them to show up in reports on the Visitors or Actions tabs. I’ve tried the command line reprocessing, dropping tables and signing out/in, to no avail.

This is the code I’m using. What am I missing?

        $pwk = new PiwikTracker( $idSite = 3, 'http://site.dev/' );
        $pwk->setTokenAuth( 'TOKEN' );
        $pwk->setIp( $record['ip'] );
        $pwk->setForceVisitDateTime( $record['date']  );
        $pwk->setCustomVariable( 1, 'VarName', 'VarValue','VarScope');
        $pwk->setUrl( $record['action'] );
        $pwk->doTrackAction( 'ActionUrl', 'ActionType' );
        $pwk->doTrackEvent( 'EventCat','EventAction','EventName',10.00 );
        $pwk->doTrackPageView( 'PageName' );


I had the same issue and fixed it by manually changing the ‘ts_created’ in the piwik_sites table to be earlier than the date on my first log entry.

I deleted all of the old archive table and reran the archive from the command line and my data then appeared correctly for the old visits and events.

I also used the ‘setForceNewVisit’ function, but you may not need that.

Also, are your values hardcoded for the ‘doTrackEvent’ function?



Royce, you’re a timesaver and this worked brilliantly. The full script includes setForceNewVisit and dynamically generated values for all the functions. Thanks so much.

(Matthieu Aubry) #4

Hi guys, thanks for the report! I’ve created an issue to keep track of this problem in: Importing historical data via the API doesn’t show in Piwik · Issue #6683 · matomo-org/matomo · GitHub