What formula can I use to calculate “page views” and “goal conversions” from the raw data?
I pulled raw data with Live.getLastVisitsDetails and tried using the following formulas, but they do not match aggregate values pulled from the API:
Page views:
Attempted calculation: count(distinct idpageview)
Aggregate data pulled from API: Action.get.nb_pageviews
Goal conversions:
Attempted calculation: sum(goalConversions)
Aggregate data pulled from API: Goals.get.nb_conversions
Relatedly, does Matomo have a metric glossary that includes technical calculations? Thanks!
Hi @inmemoryofer
Page views
You can also count where type="action"
, but your formula should work either. What is the observed difference (between your calculation and Matomo one)?
Goal conversions
With your method, you’ll get the total number of conversions. If you want to get the number of converted visits: count where goalConversions > 0
More info
You can also get data from the database:
https://developer.matomo.org/guides/database-schema
Hi @heurteph-ei, thanks so much for your response! I’m looking at a single day of data and the observed differences for pages views and goal conversions are as such:
Page Views
Calculated value: 98625
Matomo value: 97370
Goal conversions
Calculated value: 2056
Matomo value: 2134
So the numbers are close. And I feel fairly confident that I have the right data because my calculations for unique visitors (count distinct visitorId) and visits (count distinct idVisit) was spot on.
For page views, I tried filtering page views for type=“action”, which brings down my count a bit (I think because it excludes the “search” action"), but still doesn’t match the Matomo value.
For goal conversions, I can correctly calculate “visits converted to a goal” by taking the sum of visitConverted, but for some reason the count of actual goal conversions is still off.
Do you know of any other nuances for these two metrics that I could be missing? Thanks again for your help!
Hi @inmemoryofer
For Page views, maybe you have sometimes events happening on paveview ID where the pageview does not exist or belongs to the previous visit? Try to check if a visit start by an event instead of a pageview. Or if an event is not attached to a page (you can see it in the events log because the event is at the same level than a page view instead of being sub level…)
For goal conversion, for the day where you extracted data, what is the number of converted visits?