Piwik\DataAccess\LogAggregator::queryVisitsByDimension PHP Method

queryVisitsByDimension() public method

**Result Set** The following columns are in each row of the result set: - **{@link Piwik\Metrics::INDEX_NB_UNIQ_VISITORS}**: The total number of unique visitors in this group of aggregated visits. - **{@link Piwik\Metrics::INDEX_NB_VISITS}**: The total number of visits aggregated. - **{@link Piwik\Metrics::INDEX_NB_ACTIONS}**: The total number of actions performed in this group of aggregated visits. - **{@link Piwik\Metrics::INDEX_MAX_ACTIONS}**: The maximum actions perfomred in one visit for this group of visits. - **{@link Piwik\Metrics::INDEX_SUM_VISIT_LENGTH}**: The total amount of time spent on the site for this group of visits. - **{@link Piwik\Metrics::INDEX_BOUNCE_COUNT}**: The total number of bounced visits in this group of visits. - **{@link Piwik\Metrics::INDEX_NB_VISITS_CONVERTED}**: The total number of visits for which at least one conversion occurred, for this group of visits. Additional data can be selected by setting the $additionalSelects parameter. _Note: The metrics returned by this query can be customized by the $metrics parameter._
public queryVisitsByDimension ( array $dimensions = [], boolean | string $where = false, array $additionalSelects = [], boolean | array $metrics = false, boolean | Piwik\RankingQuery $rankingQuery = false ) : mixed
$dimensions array `SELECT` fields (or just one field) that will be grouped by, eg, `'referrer_name'` or `array('referrer_name', 'referrer_keyword')`. The metrics retrieved from the query will be specific to combinations of these fields. So if `array('referrer_name', 'referrer_keyword')` is supplied, the query will aggregate visits for each referrer/keyword combination.
$where boolean | string Additional condition for the `WHERE` clause. Can be used to filter the set of visits that are considered for aggregation.
$additionalSelects array Additional `SELECT` fields that are not included in the group by clause. These can be aggregate expressions, eg, `SUM(somecol)`.
$metrics boolean | array The set of metrics to calculate and return. If false, the query will select all of them. The following values can be used: - {@link Piwik\Metrics::INDEX_NB_UNIQ_VISITORS} - {@link Piwik\Metrics::INDEX_NB_VISITS} - {@link Piwik\Metrics::INDEX_NB_ACTIONS} - {@link Piwik\Metrics::INDEX_MAX_ACTIONS} - {@link Piwik\Metrics::INDEX_SUM_VISIT_LENGTH} - {@link Piwik\Metrics::INDEX_BOUNCE_COUNT} - {@link Piwik\Metrics::INDEX_NB_VISITS_CONVERTED}
$rankingQuery boolean | Piwik\RankingQuery A pre-configured ranking query instance that will be used to limit the result. If set, the return value is the array returned by {@link Piwik\RankingQuery::execute()}.
return mixed A Zend_Db_Statement if `$rankingQuery` isn't supplied, otherwise the result of {@link Piwik\RankingQuery::execute()}. Read {@link queryVisitsByDimension() this} to see what aggregate data is calculated by the query.
    public function queryVisitsByDimension(array $dimensions = array(), $where = false, array $additionalSelects = array(), $metrics = false, $rankingQuery = false)
    {
        $tableName = self::LOG_VISIT_TABLE;
        $availableMetrics = $this->getVisitsMetricFields();
        $select = $this->getSelectStatement($dimensions, $tableName, $additionalSelects, $availableMetrics, $metrics);
        $from = array($tableName);
        $where = $this->getWhereStatement($tableName, self::VISIT_DATETIME_FIELD, $where);
        $groupBy = $this->getGroupByStatement($dimensions, $tableName);
        $orderBy = false;
        if ($rankingQuery) {
            $orderBy = '`' . Metrics::INDEX_NB_VISITS . '` DESC';
        }
        $query = $this->generateQuery($select, $from, $where, $groupBy, $orderBy);
        if ($rankingQuery) {
            unset($availableMetrics[Metrics::INDEX_MAX_ACTIONS]);
            $sumColumns = array_keys($availableMetrics);
            if ($metrics) {
                $sumColumns = array_intersect($sumColumns, $metrics);
            }
            $rankingQuery->addColumn($sumColumns, 'sum');
            if ($this->isMetricRequested(Metrics::INDEX_MAX_ACTIONS, $metrics)) {
                $rankingQuery->addColumn(Metrics::INDEX_MAX_ACTIONS, 'max');
            }
            return $rankingQuery->execute($query['sql'], $query['bind']);
        }
        return $this->getDb()->query($query['sql'], $query['bind']);
    }