Skip to main content
Version: 2023.2

Installation and Configuration

Bundle Installation

For Pimcore >= 10.5

To install Pimcore Statistics Explorer for Pimcore 10.5 or higher, 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:
use Pimcore\Bundle\StatisticsExplorerBundle\PimcoreStatisticsExplorerBundle;
// ...

return [
// ...
PimcoreStatisticsExplorerBundle::class => ['all' => true],
// ...
];
  1. Install the bundle:
bin/console pimcore:bundle:install PimcoreStatisticsExplorerBundle

For Older Versions

To install the Statistics Explorer bundle for older versions of Pimcore, please run the following commands instead:

composer require pimcore/statistics-explorer
bin/console pimcore:bundle:enable PimcoreStatisticsExplorerBundle
bin/console pimcore:bundle:install PimcoreStatisticsExplorerBundle

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:

  • 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' }
Elasticsearch configuration

The ElasticsearchAdapter needs an elasticsearch cluster to work.

Elasticsearch client configuration takes place via Pimcore Elasticsearch Client Bundle

# Configure an elasticsearch client 
pimcore_elasticsearch_client:
es_clients:
default:
hosts: ['elastic:9200']
username: 'elastic'
password: 'somethingsecret'
logger_channel: 'pimcore.elasicsearch'

Pimcore Elasticsearch Client Bundle registers symfony services for each configured elasticsearch client which can be used for data sources (see above) and event trackers.

Configuration above creates a default client which is registered as service pimcore.elasticsearch_client.default.

For further configuration options (like authentication) have a look at Pimcore Elasticsearch Client Bundle.