开发者

Piwik API how to get daily visits for 7 days

开发者 https://www.devze.com 2023-03-30 17:06 出处:网络
I\'m trying to get daily visits from my instance of piwik for every day in the week. Currently this query is ret开发者_如何学Curning the sum of all my visits for the entire week. Is there any way to

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

Currently this query is ret开发者_如何学Curning 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=#########


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消