How to create a Widget that would graph result of an operation on existing data

Beeing fairly new to piwik (less then a month), I am very impress so far with what I can do.

Now I would like to graph data that would be the result of a fairly complex operations based on data already captured by piwik. What I mean is …

Our site is made of several pages. Some pages can only be access by Members, while the others are design to inform the general public.What we want to measure and graph is a fairly estimation of the number of “good” visitors; that is visitors that are not members, neither “bounced” visitors.

By the nature of the site, over a period of a month, all members do log more then ounce, while the general public pages do carry little added info for a Member, and therefore it is a good assumption to suppose that members would not visit them, except for 2 pages.

Approach 1 …
One estimate could be to substract from nb_visits, the nb_visits_returning … the latter value beeing to a high percentage made of Members … but that would probably still be an overestimate, because it do not include “bounce visitors” (around 25%). A better estimate could then be to take (1-%bounce_pages) nb_visit - nb_visits_returning .

Approach 2
Now considering that 75% of visitors first view our “welcome page”, and 5% go directly to the member login page, one approach could be to work with the entry pages data to evaluate the % of “good visitors” and apply that percentage to the nb_visits. As a matter of fact, for our site, the correlation between nb_visit and entry pages is close to 1 (0.994). Also, because it carry no valuable information, regarding members, we only track the access to the member identification page, all other pages only accessible by members being not tracked. Still we tracked from the general public pages, the 2 page that are more likely being visit by members.

The difficulty then rely on calculating the number of time that entry page to the “welcome page” was follow by a general public page then add that estimate to the total of entry pages general public type …

That calculation could be equal to :

A =
Total entry pages - total bounce

- (Sommation of entry pages dedicated to members - its bounce count) no double count on bounce
- (Sommation of unique Page views dedicated to members - its entry page value) to remove the welcome page that lead to the identification page

the % “good visitors” = A/Total entry pages

then estimation of good visitors = % “good visitors” x nb_visits

Understanding that all those data are today in piwik and available through the API, how (which php) should I investigate and modify so I can produce a widget and take advantage of the existing graphic capability ( evolution graph type). Ideally, I would like to produce both estimate describe above and display them over the same graph …

Thx in advance for any insight, example or advice. I have start looking at some guides, but what I don’t see is how to access existing data, s oppose to create a new data type . Open to any suggestion …


I recommend you use a mix of custom variables (Custom Variables Analytics - Analytics Platform - Matomo ) and segmentation (Segmentation - Compare segments of visitors - Analytics Platform - Matomo ) to show only a subset of visitors that would match the rule that you make up. Then you can easily plot this on the graph (adding &segment= … to the widget URL)