Skip to content

Commit

Permalink
Merge pull request #3214 from rbayet/feat-analytics-adding-some-KPIs
Browse files Browse the repository at this point in the history
[Analytics] Additional product/category/sales KPIs
  • Loading branch information
romainruaud authored Mar 18, 2024
2 parents ecbf0aa + 803303f commit f1c9500
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,33 @@ private function getQueries()
'value' => 'catalogsearch_result_index',
]
),
'product_views' => $this->queryFactory->create(
QueryInterface::TYPE_TERM,
[
'field' => 'page.type.identifier',
'value' => 'catalog_product_view',
]
),
'category_views' => $this->queryFactory->create(
QueryInterface::TYPE_TERM,
[
'field' => 'page.type.identifier',
'value' => 'catalog_category_view',
]
),
'add_to_cart' => $this->queryFactory->create(
QueryInterface::TYPE_EXISTS,
[
'field' => 'page.cart.product_id',
]
),
'sales' => $this->queryFactory->create(
QueryInterface::TYPE_TERM,
[
'field' => 'page.type.identifier',
'value' => 'checkout_onepage_success',
]
),
];

return $queries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class Report extends AbstractReport
* @var array
*/
private $defaultKeys = [
'page_view_counts',
'page_views_count',
'product_views_count',
'category_views_count',
'add_to_cart_count',
'sales_count',
'sessions_count',
'visitors_count',
'search_page_views_count',
Expand All @@ -49,12 +53,15 @@ protected function processResponse(\Smile\ElasticsuiteCore\Search\Adapter\Elasti
if ($value->getValue() == 'all') {
$data['sessions_count'] = (int) $value->getMetrics()['unique_sessions'];
$data['visitors_count'] = (int) $value->getMetrics()['unique_visitors'];
} else {
} elseif ($value->getValue() == 'searches') {
$data['search_page_views_count'] = (int) $value->getMetrics()['count'];
$data['search_sessions_count'] = (int) $value->getMetrics()['unique_sessions'];
$data['search_usage_rate'] = round($data['search_page_views_count'] / ($data['search_sessions_count'] ?: 1), 1);
$data['spellcheck_usage_count'] = (int) $value->getMetrics()['spellcheck_usage']['sum'];
$data['spellcheck_usage_rate'] = $value->getMetrics()['spellcheck_usage']['avg'];
} elseif (in_array($value->getValue(), ['product_views', 'category_views', 'add_to_cart', 'sales'])) {
$key = sprintf("%s_count", $value->getValue());
$data[$key] = (int) $value->getMetrics()['count'];
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/module-elasticsuite-analytics/i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"Searches","Searches"
"Page views","Page views"
"Category views","Category views"
"Product views","Product views"
"Products added to cart","Products added to cart"
"Sales","Sales"
"Sessions","Sessions"
"Sessions with search","Sessions with search"
"Sessions without search","Sessions without search"
Expand Down
4 changes: 4 additions & 0 deletions src/module-elasticsuite-analytics/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"Searches","Recherches"
"Page views","Pages vues"
"Category views","Catégories vues"
"Product views","Produits vus"
"Products added to cart","Ajouts au panier"
"Sales","Ventes"
"Sessions","Sessions"
"Sessions with search","Sessions avec recherche"
"Sessions without search","Sessions sans recherche"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,84 @@
$data = $block->getKpi();
?>

<div class="dashboard-main col-m-10 col-m-push-1">
<div class="dashboard-main col-m-11">
<div class="dashboard-totals">
<?php if (empty($data)) : ?>
<div class="empty-text" style="width:100%; text-align:center">
<em><?= __('No data over the selected period.'); ?></em>
</div>
<?php else : ?>
<ul class="dashboard-totals-list">
<li class="dashboard-totals-item" style="width:16%; text-align:center;">
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Searches') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['search_page_views_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item" style="width:16%; text-align:center;">
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Page views') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['page_views_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item" style="width:16%; text-align:center;">
<span class="dashboard-totals-label"><?= __('Sessions') ?></span>
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Category views') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['sessions_count']; ?></span>
<span class="value"><?= $data['category_views_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item" style="width:16%; text-align:center;">
<span class="dashboard-totals-label"><?= __('Sessions with search') ?></span>
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Product views') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['search_sessions_count']; ?></span>
<span class="value"><?= $data['product_views_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item" style="width:16%; text-align:center;">
<span class="dashboard-totals-label"><?= __('Searches per session') ?></span>
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Products added to cart') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['search_usage_rate']; ?></span>
<span class="value"><?= $data['add_to_cart_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Sales') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['sales_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item" style="width:16%; text-align:center;">
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Visitors') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['visitors_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Sessions') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['sessions_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Sessions with search') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['search_sessions_count']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
<li class="dashboard-totals-item">
<span class="dashboard-totals-label"><?= __('Searches per session') ?></span>
<strong class="dashboard-totals-value">
<span class="value"><?= $data['search_usage_rate']; ?></span>
<span class="dashboard-totals-decimals"></span>
</strong>
</li>
</ul>
<?php endif; ?>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
display: none;
}

.dashboard-totals-list {
.dashboard-totals-item {
width: 10%;
text-align: center
}
}

.admin__table-primary {
&.dashboard-data {
&.terms-report {
Expand Down

0 comments on commit f1c9500

Please sign in to comment.