Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
is would be great to define your own period for a field. Like "Last 2 days".
Comments
Comment #1
patrickd CreditAttribution: patrickd commentedthanks for your request,
unfortunately this is a little complicated as piwik either wants the period to be a string like "day", "week", "month", "year" or it wants to have a specific date "range". That means that a string like "last 2 days" must be converted into a date range. (See piwik API documentation for reference).
To make a good implementation of this we need to find an elegant way to transform thresholds into date ranges
Comment #2
Erik Seifert CreditAttribution: Erik Seifert commentedHow about make a field config ?
Period: custom
Range: 22.12.2011 - 24.12.2011
Comment #3
patrickd CreditAttribution: patrickd commentedyes that would be easily possible, but that would not make possible to define it like "last two days" (unless you edit the fields config every day). I already thought about just making this range setting available but I couldn't think of any usecase worth the effort. (why does somebody just want static node statistics from a date range?)
Comment #4
Erik Seifert CreditAttribution: Erik Seifert commentedExample ;-)
Now day period show hits for only this day 00:00 - 24:00 . But we need the last 24 Hours ;- ) So if you look on the website at 00:01 , no entry appears.
Comment #5
patrickd CreditAttribution: patrickd commentedyes but custom ranges won't help in your example
Period: custom
Range: 22.12.2011 - 24.12.2011
now you have to change the date every day manually, otherwise it will show statistics from 22.12.2011 - 24.12.2011
What you need is a custom dynamic range like
"last two days"
and this must automatically be translated into
[current date - 2days] until [current date]
before submitting it to piwik api
this is the problem I meant with - how to solve this in an elegant way
Comment #6
Erik Seifert CreditAttribution: Erik Seifert commentedGive me some days. I will think it over ;- )
Comment #7
Romka CreditAttribution: Romka commentedWhat do you think about next solution?
First, I propose to add new parameters to widget settings ('range-2' and 'range-3' in this example):
Then add next code to the function piwik_stats_api_request:
In result this function would look like this:
Comment #8
patrickd CreditAttribution: patrickd commentedwould be a way, but this means all ranges are hardcoded and only the ranges available in the select box can be chosen,
I'd rather like to have a "Range" item in the period select and if you select range another textfield apears where you can enter a range like "+2 days", "+6 hours", etc.
This string can then be translated into a range of the "current_time" until "strtotime(range, current_time)".
$date = date('Y-m-d', strtotime($range)) . ',' . date('Y-m-d');
Comment #9
Erik Seifert CreditAttribution: Erik Seifert commentedWhat about this:
http://php.net/manual/de/datetime.formats.relative.php
Comment #10
patrickd CreditAttribution: patrickd commentedmarked #2058935: Statistics field settings 'Period' as duplicate of this feature request.
Comment #11
phem CreditAttribution: phem commentedthis is my solution:
See http://piwik.org/docs/analytics-api/reference/ for explanation of lastX and previousX