matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.83k stars 2.64k forks source link

Static PNG Graph: plot several metrics & multiple row evolutions #3013

Open mattab opened 12 years ago

mattab commented 12 years ago

It would be very nice of the Static Image Graph API could plot several metrics at once, similarly to the JS graphs.

For example we could plot Visits and Pageviews on the same graphs with: index.php?module=API&method=ImageGraph.get&idSite=3&apiModule=VisitsSummary&apiAction=get&token_auth=anonymous&graphType=evolution&period=day&date=previous30&width=500&height=250&columns=nb_actions,nb_visits

The Static Image Graph API should also support a new parameter named &labels to plot multiple row evolutions.

julienmoumne commented 12 years ago

Attachment: VisitFrequency with multiple metrics.png

julienmoumne commented 12 years ago

Attachment: Referers.getRefererType with multiple metrics.png

julienmoumne commented 12 years ago

Attachment: UserSettings.getPlugin with multiple metrics (mobile size).png

julienmoumne commented 12 years ago

Attachment: &labels=Search Engines,Direct Entry,Websites&columns=nb_actions Referers.getRefererType row evolution.png

julienmoumne commented 12 years ago

Attachment: http://dev.piwik.org/trac/ticket/3158#comment:3 getRowEvolution now supports $idGoal Goals getVisitsUntilConversion ecommerceOrder last5 months LABEL=1 VISIT.png

mattab commented 12 years ago

This feature would be very useful for:

julienmoumne commented 12 years ago

This ticket seems to be more than plotting multiple metrics.

3014 requires the ImageGraph plugin to also plot row(s) evolution.

The first question we need to answer is whether we :

If the first option is selected, we need to define when should the Row Evolution API be solicited.

Here are the main two cases I could think of :

This evolution will also require to update the Metadata imageGraphUrl field.

The current behavior of the imageGraphUrl is as follow :

After updating the ImageGraph API to support row(s) evolution, we need to determine the value of the imageGraphUrl field for the first case (API.getMetadata Referers.get period=day date=last30).

Instead of rewriting &period &date, the imageGraphUrl would contain an API call which returns row evolution. However, we need to decide which label(s) should be drawn. Ideally, we could plot all labels. This gets complicated when the report does not have a constant number of labels (constantRowsCount!=1) or when the number of rows is too big.

mattab commented 12 years ago

Replying to JulienM:

This ticket seems to be more than plotting multiple metrics.

3014 requires the ImageGraph plugin to also plot row(s) evolution.

Thank you for your great analysis :)

The first question we need to answer is whether we :

  • add a new &labels parameter to ImageGraph.get, or

I think this solution is nice indeed!

Here are the main two cases I could think of :

  • when at least one row label is provided via the &labels parameter
  • when &period &date correspond to multiple periods and the requested report has a dimension (such as Referrers, UserSettings, UserCountry and so on). Currently, ImageGraph.get generates an error see The graph cannot be drawn for this combination of 'date' and 'period' parameters.
  • should both cases above be required to solicitate the Row Evolution API or should one be sufficient ? For example, if no labels are supplied, maybe we could automatically plot ALL labels?

Agreed that when no labels are supplied, we could plot the evolution of the top 5 labels for example ?

After updating the ImageGraph API to support row(s) evolution, we need to determine the value of the imageGraphUrl field for the first case (API.getMetadata Referers.get period=day date=last30).

Instead of rewriting &period &date, the imageGraphUrl would contain an API call which returns row evolution. However, we need to decide which label(s) should be drawn. Ideally, we could plot all labels. This gets complicated when the report does not have a constant number of labels (constantRowsCount!=1) or when the number of rows is too big.

Plotting all labels it not so possible, because above 5 lines the graph becomes hard to read.

--> &labels and &filter_limit support sounds like perfect API evolution for this feature!

There is also an open question about how to plot Ecommerce metrics, Goal metrics, on the graph. Maybe in a different ticket we could propose to have &enhanced=1 parameter that would return the goal/ecommerce metrics as well.

julienmoumne commented 12 years ago

Pending comment:3:ticket:3158.

If it can't be fixed, we can throw an exception when trying to plot row evolutions for Goal reports when Piwik_ImageGraph_API.get $idGoal is not empty.

We would also need to alter the imageGraphUrl construction logic to switch back to non-evolution graph.

julienmoumne commented 12 years ago

The logic to retrieve the top 5 row evolutions should maybe be part of #3158, see comment:4:ticket:3158.

mattab commented 12 years ago

Very nice graphs!!

If it can't be fixed, we can throw an exception when trying to plot row evolutions for Goal reports when Piwik_ImageGraph_API.get $idGoal is not empty. You meant "when idGoal is empty" I suppose?

We would also need to alter the imageGraphUrl construction logic to switch back to non-evolution graph. +1

  • As noted before, the row evolution should not require the &labels= parameter (for example to plot evolution of referrer types, &labels is not required)
  • This new ability to plot multiple values at once will be great when we implement "Compare the monthly report to the last month" #291 and we could show, on the graph, the values for the current and previous month...
julienmoumne commented 12 years ago

(In [6918]) refs #3013

refs #3014

refs #3158

constantRowsCount set on

merges

IDEA

TODO

mattab commented 12 years ago

Great patch and improvements! :)

--> This other way to solve would be better than the committed fix: sometimes it is important to delete the rows that have visits=0 but some conversions, because sometimes the "Keywords" or "websites" used in previous visits can be credited a "conversion" if they are the last referrer.

So not deleting the conversion==0 row in this datatable would result in the UI showing rows with 0 visits which was a bug we fixed with this code to delete rows :)


    1135                            // retrieve top labels 
    1136                            $dataTableArray = $this->loadRowEvolutionDataFromAPI( 
    1137                                    $idSite, 
    1138                                    $period, 
    1139                                    $date, 
    1140                                    $apiModule, 
    1141                                    $apiAction, 
    1142                                    null, 
    1143                                    $segment, 
    1144                                    $idGoal 
    1145                            ); 
    1146     
    1147                            // get the last, ie. most recent, datatable 
    1148                            $dataTables = $dataTableArray->getArray(); 
    1149                            $mostRecentDataTable = end($dataTables); 
    1150     
    1151                            $labels = $mostRecentDataTable->getColumn('label'); 

Here it would be more efficient to directly call the API using Piwik_API_Request() and http_build_query() to build the request string. The advantage will be better performance since you can only request the last period's worth of data.

You should be able to use the functions: Piwik_Archive::isMultiplePeriod and Piwik_Period_Range($dateString) to get the last date of the range.

let me know if there is any problem doing this change? it will speed up graphs.


1244    1269                    // add "processed metrics" like actions per visit or bounce rate 
1245                        if ($apiModule != 'Actions') 
    1270                    if ($apiModule != 'Actions' && $label) 
julienmoumne commented 12 years ago

(In [6925]) refs #3158

refs #3013

mattab commented 12 years ago

paste due to misclick on my new laptop ;)

julienmoumne commented 12 years ago

(In [6947]) refs #1721 refs #3013

julienmoumne commented 12 years ago

(In [6951]) refs #1721 refs #3013

julienmoumne commented 12 years ago

(In [6969]) refs #3013

julienmoumne commented 12 years ago

(In [6970]) refs #3013

julienmoumne commented 12 years ago

(In [6982]) refs #3013

julienmoumne commented 12 years ago

(In [7009]) refs #3013

mattab commented 12 years ago

This is a test comment but a real comment too, awesome work & can't wait to see the next improvements ;-)

julienmoumne commented 12 years ago

(In [7026]) refs #3013

julienmoumne commented 12 years ago

(In [7077]) refs #3013

julienmoumne commented 12 years ago

(In [7078]) refs #3013

julienmoumne commented 12 years ago

(In [7079]) refs #3013

julienmoumne commented 12 years ago

(In [7086])

refs #3158 refs #3013

refs #3158

julienmoumne commented 12 years ago

(In [7088]) refs #3013

julienmoumne commented 12 years ago

(In [7102]) refs #3013

mattab commented 12 years ago

(In [Refs #3013 I'm in a rush, but I had to add this code as the $periodsData$i) was NULL in my case, not sure why it hasn't been needed until now, so maybe there is an underlying problem in Site Search, or maybe this change is acceptable...?

mattab commented 12 years ago

(In [7303]) Fixes #3474

Ping Refs #3013

mattab commented 11 years ago

This ticket is getting long, What is the status of #3013?