Skip to main content
Version: 2024.4

Installation and Configuration

Bundle Installation

To install Pimcore Statistics Explorer, follow the three steps below:

  1. Install the required dependencies:
composer require pimcore/statistics-explorer
  1. Make sure the bundle is enabled in the config/bundles.php file. The following lines should be added:
return [
// ...
Pimcore\Bundle\StatisticsExplorerBundle\PimcoreStatisticsExplorerBundle::class => ['all' => true],
// ...
];
  1. Install the bundle:
bin/console pimcore:bundle:install PimcoreStatisticsExplorerBundle

Deployment hint

For deployments of applications with this bundle via deployment pipelines without actual database access, the Symfony cache warming process could fail as doctrine ORM tries to determine the database version on cache warm-up to build its cache. Therefore, it is recommended to configure the database server version in the default DBAL connection like this:

doctrine:
dbal:
default_connection: default
connections:
default:
...
server_version: mariadb-10.11.0

Configuration

The statistics explorer needs to be embedded into an existing host application that provides the context in which the statistics explorer is executed.

The statistics explorer can be executed in multiple contexts within one host application and each context is connected to user & login information. The name for contexts can be freely selected, example would be pimcore_admin, portal, frontend, ...

To set up a context and embed the statistics explorer, there are three additional setup steps necessary besides the actual installation of the bundle.

Setup User Provider

The host application needs to take about user authentication (e.g. via a symfony firewall) and provide the statistics explorer the user information.

This is done by creating a service that is implementing the UserProviderInterface and that is tagged with the pimcore.statistics_explorer.user_provider_context tag which defines the context the user provider is for. This service has methods to return the current logged-in user and other users that configurations can be shared with.

The bundle ships with a sample implementation for Pimcore users which also can be used for your application.

Sample User Provider Configuration
    statistics_explorer.userprovider_portal:
autowire: true
autoconfigure: true
public: false
class: Pimcore\Bundle\StatisticsExplorerBundle\User\PimcoreUserProvider
tags:
- { name: 'pimcore.statistics_explorer.user_provider_context', context: 'portal' }

Setup Routes

All controller actions of the statistics explorer need to be executed in the defined context and most probably in the context of the corresponding firewall. To provide maximal flexibility, the statistics explorer does not predefine any routes but allows you to define the route prefix(es) in which the statistics explorer should be reachable.

This can be done by adding following entry to your routing.yml whereas the prefix can be selected freely.

pimcore_statistics_explorer:
resource: "@PimcoreStatisticsExplorerBundle/Controller"
type: annotation
prefix: /admin/stats

The urls for statistics explorer will add the context name and the actual action to it, and look like similar as /admin/stats/portal/data-sources.

See also Using Statistics Explorer and Using Statistics Loader for further details.

Setup Data Sources

The last setup step is to configure data sources that should be used by the statistics explorer. Data sources are symfony services that implement the StatisticsStorageAdapterInterface and are tagged with the pimcore.statistics_explorer.data_source which defines the data source name and the context in which it should be available.

As an alternative to tagged services, there is also the possibility to add data sources during runtime via events.

The bundle ships with two implementations for the interface which can be used right away to define data sources:

  • OpensearchAdapter
    • expects Opensearch client and index name as argument.
    • Supports Opensearch versions 2.
  • ElasticsearchAdapter
    • expects Elasticsearch client and index name as argument.
    • Supports Elasticsearch versions 8.
  • MySqlAdapter
    • expects table name as argument
    • optionally, a Connection can be provided to specify a special database connection (by default the default Pimcore connection is used)

By implementing the interface, also additional data sources could be supported.

Sample Data Source Configuration
    datasources.data_objects_car:
class: Pimcore\Bundle\StatisticsExplorerBundle\StatisticsStorageAdapter\ElasticsearchAdapter
autowire: true
autoconfigure: true
public: false
arguments:
$esClient: '@pimcore.elasticsearch_client.default'
$indexName: 'data_objects_car'
$label: 'Data Objects Car'
tags:
- { name: 'pimcore.statistics_explorer.data_source', 'dataSourceName': 'data_objects_car', context: 'portal' }


datasources.assets:
autowire: true
autoconfigure: true
public: false
class: Pimcore\Bundle\StatisticsExplorerBundle\StatisticsStorageAdapter\MySqlAdapter
arguments:
$tableName: 'assets'
$label: 'Assets'
tags:
- { name: 'pimcore.statistics_explorer.data_source', 'dataSourceName': 'assets', context: 'portal' }
- { name: 'pimcore.statistics_explorer.data_source', 'dataSourceName': 'assets', context: 'another_portal' }