Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation of action custom dimension metrics #22571

Draft
wants to merge 7 commits into
base: 5.x-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions plugins/CustomDimensions/RecordBuilders/CustomDimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ protected function aggregateFromActions(DataTable $report, LogAggregator $logAgg
{
$metricsConfig = ActionsMetrics::getActionMetrics();

$resultSet = $this->queryCustomDimensionActions($metricsConfig, $logAggregator, $valueField);

$metricIds = array_keys($metricsConfig);
$metricIds[] = Metrics::INDEX_PAGE_SUM_TIME_SPENT;
$metricIds[] = Metrics::INDEX_BOUNCE_COUNT;
$metricIds[] = Metrics::INDEX_PAGE_EXIT_NB_VISITS;

$resultSet = $this->queryCustomDimensions($metricsConfig, $logAggregator, $valueField);

while ($row = $resultSet->fetch()) {
if (!isset($row[Metrics::INDEX_NB_VISITS])) {
return;
Expand All @@ -193,10 +193,28 @@ protected function aggregateFromActions(DataTable $report, LogAggregator $logAgg
$columns[$id] = (float) ($row[$id] ?? 0);
}

$tableRow = $report->sumRowWithLabel($label, $columns);
$report->sumRowWithLabel($label, $columns);
}

$resultSet = $this->queryCustomDimensionActions($metricsConfig, $logAggregator, $valueField);

while ($row = $resultSet->fetch()) {
if (!isset($row[Metrics::INDEX_NB_VISITS])) {
return;
}

$label = $row[$valueField];
$label = $this->cleanCustomDimensionValue($label);

$columns = [];
foreach ($metricIds as $id) {
$columns[$id] = (float) ($row[$id] ?? 0);
}

$tableRow = $report->getRowFromLabel($label);

$url = $row['url'];
if (empty($url)) {
if (empty($url) || empty($tableRow)) {
continue;
}

Expand All @@ -212,10 +230,16 @@ protected function aggregateFromActions(DataTable $report, LogAggregator $logAgg
}
}

public function queryCustomDimensionActions(array $metricsConfig, LogAggregator $logAggregator, $valueField, $additionalWhere = '')
protected function queryCustomDimensions(array $metricsConfig, LogAggregator $logAggregator, $valueField, $additionalDimensions = [], $additionalWhere = '')
{
$additionalSelects = '';

foreach ($additionalDimensions as $name => $selectField) {
$additionalSelects .= "$selectField as $name,";
}

$select = "log_link_visit_action.$valueField,
log_action.name as url,
$additionalSelects
sum(log_link_visit_action.time_spent) as `" . Metrics::INDEX_PAGE_SUM_TIME_SPENT . "`,
sum(case log_visit.visit_total_actions when 1 then 1 when 0 then 1 else 0 end) as `" . Metrics::INDEX_BOUNCE_COUNT . "`,
sum(IF(log_visit.last_idlink_va = log_link_visit_action.idlink_va, 1, 0)) as `" . Metrics::INDEX_PAGE_EXIT_NB_VISITS . "`";
Expand All @@ -241,15 +265,21 @@ public function queryCustomDimensionActions(array $metricsConfig, LogAggregator
$where .= ' AND ' . $additionalWhere;
}

$groupBy = "log_link_visit_action.$valueField, url";
$groupBy = "log_link_visit_action.$valueField";

foreach ($additionalDimensions as $name => $selectField) {
$groupBy .= ", $name";
}

$orderBy = "`" . Metrics::INDEX_PAGE_NB_HITS . "` DESC";

// get query with segmentation
$query = $logAggregator->generateQuery($select, $from, $where, $groupBy, $orderBy);

if ($this->rankingQueryLimit > 0) {
$rankingQuery = new RankingQuery($this->rankingQueryLimit);
$rankingQuery->addLabelColumn([$valueField, 'url']);

$rankingQuery->addLabelColumn(array_merge([$valueField], array_keys($additionalDimensions)));

$sumMetrics = [
Metrics::INDEX_PAGE_SUM_TIME_SPENT,
Expand All @@ -276,6 +306,11 @@ public function queryCustomDimensionActions(array $metricsConfig, LogAggregator
return $resultSet;
}

public function queryCustomDimensionActions(array $metricsConfig, LogAggregator $logAggregator, $valueField, $additionalWhere = '')
{
return $this->queryCustomDimensions($metricsConfig, $logAggregator, $valueField, ['url' => 'log_action.name'], $additionalWhere);
}

private function getRankingQueryLimit(): int
{
$configGeneral = Config::getInstance()->General;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ protected function trackFirstVisit()
$t->setUrl('http://example.com/sub_en/page?param=en_US');
self::checkResponse($t->doTrackPageView('Third page view'));

$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.4)->getDatetime());
$t->setUrl('http://example.com/sub_en/page?param=en_US');
self::checkResponse($t->doTrackPageView('Fourth page view'));

$t->setForceVisitDateTime(Date::factory($this->dateTime)->addDay(0.4)->getDatetime());
$t->setUrl('http://example.com/sub_en/page?param=en_US');
self::checkResponse($t->doTrackPageView('Fourth page view'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<pageIdAction>6</pageIdAction>


<pageId>4</pageId>
<pageId>5</pageId>
<bandwidth />
<timeSpent>0</timeSpent>
<timeSpentPretty>0s</timeSpentPretty>
Expand All @@ -34,7 +34,7 @@
<goalId>1</goalId>

<revenue>0</revenue>
<goalPageId>4</goalPageId>
<goalPageId>5</goalPageId>

<url>http://example.com/sub_en/page?param=en_US</url>
<referrerType>direct</referrerType>
Expand Down Expand Up @@ -160,7 +160,7 @@
<pageIdAction>6</pageIdAction>


<pageId>6</pageId>
<pageId>7</pageId>
<bandwidth />
<timeSpent>0</timeSpent>
<timeSpentPretty>0s</timeSpentPretty>
Expand All @@ -180,7 +180,7 @@
<goalId>1</goalId>

<revenue>0</revenue>
<goalPageId>6</goalPageId>
<goalPageId>7</goalPageId>

<url>http://example.com/sub_en/page?param=en_US</url>
<referrerType>direct</referrerType>
Expand Down Expand Up @@ -306,7 +306,7 @@
<pageIdAction>6</pageIdAction>


<pageId>5</pageId>
<pageId>6</pageId>
<bandwidth />
<timeSpent>0</timeSpent>
<timeSpentPretty>0s</timeSpentPretty>
Expand All @@ -326,7 +326,7 @@
<goalId>1</goalId>

<revenue>0</revenue>
<goalPageId>5</goalPageId>
<goalPageId>6</goalPageId>

<url>http://example.com/sub_en/page?param=en_US</url>
<referrerType>direct</referrerType>
Expand Down Expand Up @@ -516,8 +516,8 @@

<pageId>3</pageId>
<bandwidth />
<timeSpent>0</timeSpent>
<timeSpentPretty>0s</timeSpentPretty>
<timeSpent>360</timeSpent>
<timeSpentPretty>6 min 0s</timeSpentPretty>
<pageviewPosition>3</pageviewPosition>
<title>Third page view</title>
<subtitle>http://example.com/sub_en/page?param=en_US</subtitle>
Expand All @@ -528,6 +528,27 @@
<dimension5>en_US</dimension5>
<bandwidth_pretty>0 M</bandwidth_pretty>
</row>
<row>
<type>action</type>
<url>http://example.com/sub_en/page?param=en_US</url>
<pageTitle>Fourth page view</pageTitle>
<pageIdAction>6</pageIdAction>


<pageId>4</pageId>
<bandwidth />
<timeSpent>0</timeSpent>
<timeSpentPretty>0s</timeSpentPretty>
<pageviewPosition>4</pageviewPosition>
<title>Fourth page view</title>
<subtitle>http://example.com/sub_en/page?param=en_US</subtitle>
<icon />
<iconSVG>plugins/Morpheus/images/action.svg</iconSVG>

<dimension3>en</dimension3>
<dimension5>en_US</dimension5>
<bandwidth_pretty>0 M</bandwidth_pretty>
</row>
</actionDetails>
<goalConversions>1</goalConversions>
<siteCurrency>USD</siteCurrency>
Expand Down Expand Up @@ -555,11 +576,11 @@
<secondsSinceFirstVisit>0</secondsSinceFirstVisit>
<daysSinceLastEcommerceOrder>0</daysSinceLastEcommerceOrder>
<secondsSinceLastEcommerceOrder />
<visitDuration>722</visitDuration>
<visitDurationPretty>12 min 2s</visitDurationPretty>
<visitDuration>1082</visitDuration>
<visitDurationPretty>18 min 2s</visitDurationPretty>
<searches>0</searches>
<actions>3</actions>
<interactions>3</interactions>
<actions>4</actions>
<interactions>4</interactions>
<referrerType>direct</referrerType>
<referrerTypeName>Direct Entry</referrerTypeName>
<referrerName />
Expand Down Expand Up @@ -640,7 +661,7 @@
<pageIdAction>10</pageIdAction>


<pageId>9</pageId>
<pageId>10</pageId>
<bandwidth />
<timeSpent>0</timeSpent>
<timeSpentPretty>0s</timeSpentPretty>
Expand All @@ -660,7 +681,7 @@
<goalId>1</goalId>

<revenue>0</revenue>
<goalPageId>9</goalPageId>
<goalPageId>10</goalPageId>

<url>http://example.com/sub_en/page</url>
<referrerType>direct</referrerType>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
<row>
<label>en</label>
<nb_visits>4</nb_visits>
<nb_hits>4</nb_hits>
<nb_hits>5</nb_hits>
<bounce_rate>75%</bounce_rate>
<avg_time_on_dimension>00:01:30</avg_time_on_dimension>
<exit_rate>75%</exit_rate>
<avg_time_on_dimension>00:01:12</avg_time_on_dimension>
<exit_rate>100%</exit_rate>
</row>
<row>
<label>value3</label>
Expand All @@ -71,8 +71,8 @@
<nb_visits>1</nb_visits>
<nb_hits>1</nb_hits>
<bounce_rate>0%</bounce_rate>
<avg_time_on_dimension>00:00:00</avg_time_on_dimension>
<exit_rate>100%</exit_rate>
<avg_time_on_dimension>00:06:00</avg_time_on_dimension>
<exit_rate>0%</exit_rate>
</row>
<row>
<label>Value not defined</label>
Expand Down Expand Up @@ -107,7 +107,7 @@
</reportMetadata>
<reportTotal>
<nb_visits>7</nb_visits>
<nb_hits>7</nb_hits>
<nb_hits>8</nb_hits>
<sum_time_network>0</sum_time_network>
<nb_hits_with_time_network>0</nb_hits_with_time_network>
<min_time_network>0</min_time_network>
Expand Down Expand Up @@ -136,7 +136,7 @@
<nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
<min_bandwidth>0</min_bandwidth>
<max_bandwidth>0</max_bandwidth>
<sum_time_spent>720</sum_time_spent>
<sum_time_spent>1080</sum_time_spent>
<bounce_count>4</bounce_count>
<exit_nb_visits>5</exit_nb_visits>
<sum_daily_nb_uniq_visitors>7</sum_daily_nb_uniq_visitors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
<row>
<label>value5 1</label>
<nb_visits>1</nb_visits>
<nb_actions>3</nb_actions>
<nb_actions_per_visit>3</nb_actions_per_visit>
<avg_time_on_site>00:12:02</avg_time_on_site>
<nb_actions>4</nb_actions>
<nb_actions_per_visit>4</nb_actions_per_visit>
<avg_time_on_site>00:18:02</avg_time_on_site>
<bounce_rate>0%</bounce_rate>
</row>
<row>
Expand All @@ -87,9 +87,9 @@
</reportMetadata>
<reportTotal>
<nb_visits>3</nb_visits>
<nb_actions>5</nb_actions>
<max_actions>3</max_actions>
<sum_visit_length>723</sum_visit_length>
<nb_actions>6</nb_actions>
<max_actions>4</max_actions>
<sum_visit_length>1083</sum_visit_length>
<bounce_count>2</bounce_count>

<goals>
Expand All @@ -103,6 +103,6 @@
<revenue>0</revenue>
<sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors>
<sum_daily_nb_users>0</sum_daily_nb_users>
<nb_actions_per_visit>1.7</nb_actions_per_visit>
<nb_actions_per_visit>2</nb_actions_per_visit>
</reportTotal>
</result>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<label>value5 1</label>
<nb_uniq_visitors>1</nb_uniq_visitors>
<nb_visits>1</nb_visits>
<nb_actions>3</nb_actions>
<max_actions>3</max_actions>
<sum_visit_length>722</sum_visit_length>
<nb_actions>4</nb_actions>
<max_actions>4</max_actions>
<sum_visit_length>1082</sum_visit_length>
<bounce_count>0</bounce_count>

<goals>
Expand All @@ -19,9 +19,9 @@
<nb_conversions>1</nb_conversions>
<revenue>0</revenue>

<avg_time_on_site>722</avg_time_on_site>
<avg_time_on_site>1082</avg_time_on_site>
<bounce_rate>0%</bounce_rate>
<nb_actions_per_visit>3</nb_actions_per_visit>
<nb_actions_per_visit>4</nb_actions_per_visit>
<segment>dimension1==value5+1</segment>
</row>
<row>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<label>en_US</label>
<nb_uniq_visitors>1</nb_uniq_visitors>
<nb_visits>1</nb_visits>
<nb_actions>3</nb_actions>
<max_actions>3</max_actions>
<sum_visit_length>722</sum_visit_length>
<nb_actions>4</nb_actions>
<max_actions>4</max_actions>
<sum_visit_length>1082</sum_visit_length>
<bounce_count>0</bounce_count>


<avg_time_on_site>722</avg_time_on_site>
<avg_time_on_site>1082</avg_time_on_site>
<bounce_rate>0%</bounce_rate>
<nb_actions_per_visit>3</nb_actions_per_visit>
<nb_actions_per_visit>4</nb_actions_per_visit>
<segment>dimension2==en_US</segment>
</row>
<row>
Expand Down

This file was deleted.

Loading
Loading