Analyzing class Piwik\DataAccess\LogAggregator
Description
Contains methods that calculate metrics by aggregating log data (visits, actions, conversions, ecommerce items).
You can use the methods in this class within {@link Piwik\Plugin\Archiver Archiver} descendants to aggregate log data without having to write SQL queries.
Aggregation Dimension
All aggregation methods accept a dimension parameter. These parameters are important as they control how rows in a table are aggregated together.
A dimension is just a table column. Rows that have the same values for these columns are aggregated together. The result of these aggregations is a set of metrics for every recorded value of a dimension.
Note: A dimension is essentially the same as a GROUP BY field.
Examples
Aggregating visit data**
$archiveProcessor = // ... $logAggregator = $archiveProcessor->getLogAggregator();
// get metrics for every used browser language of all visits by returning visitors $query = $logAggregator->queryVisitsByDimension( $dimensions = array('log_visit.location_browser_lang'), $where = 'log_visit.visitor_returning = 1',
// also count visits for each browser language that are not located in the US $additionalSelects = array('sum(case when log_visit.location_country <> 'us' then 1 else 0 end) as nonus'),
// we're only interested in visits, unique visitors & actions, so don't waste time calculating anything else $metrics = array(Metrics::INDEX_NB_UNIQ_VISITORS, Metrics::INDEX_NB_VISITS, Metrics::INDEX_NB_ACTIONS), ); if ($query === false) { return; }
while ($row = $query->fetch()) { $uniqueVisitors = $row[Metrics::INDEX_NB_UNIQ_VISITORS]; $visits = $row[Metrics::INDEX_NB_VISITS]; $actions = $row[Metrics::INDEX_NB_ACTIONS];
// ... do something w/ calculated metrics ... }
Aggregating conversion data**
$archiveProcessor = // ... $logAggregator = $archiveProcessor->getLogAggregator();
// get metrics for ecommerce conversions for each country $query = $logAggregator->queryConversionsByDimension( $dimensions = array('log_conversion.location_country'), $where = 'log_conversion.idgoal = 0', // 0 is the special ecommerceOrder idGoal value in the table
// also calculate average tax and max shipping per country $additionalSelects = array( 'AVG(log_conversion.revenue_tax) as avg_tax', 'MAX(log_conversion.revenue_shipping) as max_shipping' ) ); if ($query === false) { return; }
while ($row = $query->fetch()) { $country = $row['location_country']; $numEcommerceSales = $row[Metrics::INDEX_GOAL_NB_CONVERSIONS]; $numVisitsWithEcommerceSales = $row[Metrics::INDEX_GOAL_NB_VISITS_CONVERTED]; $avgTaxForCountry = $row['avg_tax']; $maxShippingForCountry = $row['max_shipping'];
// ... do something with aggregated data ... }
Type hierarchy
-
piwik/piwik 15477.x-dev 15414.x-dev 15307.x-dev 6265.x-dev 15534.x-dev 14944.x-dev 14939.x-dev 14054.x-dev 13835.x-dev 15176.x-dev 14744.x-dev 14612.x-dev 14428.x-dev 14395.x-dev 14223.x-dev 14188.x-dev 13989.x-dev 13383.x-dev 13325.x-dev 13272.x-dev 13070.x-dev 11942.x-dev 10801.x-dev 7105.x-dev 5711.x-dev 539.x-dev 11058.x-dev 13246.x-dev 16501.x-dev 16481.x-dev