Casey Flynn
Casey Flynn

Reputation: 14048

Piwik API how to get daily visits for 7 days

I'm trying to get daily visits from my instance of piwik for every day in the week.

Currently this query is returning the sum of all my visits for the entire week. Is there any way to separate this out into days?

http://piwikexample.com/?module=API&method=VisitsSummary.getVisits&idSite=1&period=range&date=2011-08-18,2011-08-25&format=json&token_auth=#########

Upvotes: 2

Views: 2669

Answers (2)

skplunkerin
skplunkerin

Reputation: 2383

Piwik's documentation isn't the best

I had to use the old-fashioned trial-and-error approach.

There are 3 ways, if you have period set right:

  1. lastX
    • This returns the last X days, including current day.
    • i.e. &period=day&date=last10
  2. previousX
    • This returns the previous X days, excluding today.
    • i.e. &period=day&date=previous10
  3. date range
    • &period=day&date=2011-08-18,2011-08-25

Just make sure you use period=day instead of period=range and you'll be good to go. See this note from the API:

Note: if you set 'period=range' to request data for a custom date range, the API will return the sum of data for the specified date range.

Reference: Reporting API (date) section

Upvotes: 1

Casey Flynn
Casey Flynn

Reputation: 14048

Actually figured it out. What I was missing is:

lastX for the last X periods including today (eg &date=last10&period=day would return an entry for each of the last 10 days including today). This is relative to the website timezone.

From http://piwik.org/docs/analytics-api/reference/#API

Upvotes: 7

Related Questions