Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This project is not covered by Drupal’s security advisory policy.
The Statistics API/Framework module allows applications or other contrib modules to track
numerical entries, either globally or related to a specific entity or entity
type. Examples are:
- How many times a specific content item has been viewed in general.
- How many times a specific page has been viewed by a specific user.
- How many times a specific user has logged in.
- How many times a specific file has been downloaded by anyone on the site.
- How many orders have been placed by a user.
Usage
The Statistics API module does not provide any features by itself. It needs to
be utilized by other contrib or custom modules to implement meaningful functionality.
Examples:
// Get the statistics storage.
$statistics = \Drupal::service('statistics_api.storage');
// Set to 12 the number of orders belonging to user 1.
$statistics->insertOrUpdate(
'nb_entities',
12,
'commerce_order',
0,
1
);
// Increment the number of views the content item with ID 1has received.
$statistics->increment('nb_views', 'node', 1);
// Fetch the number of views the content item with ID 1 has received.
$statistics->fetchValue('nb_views', 'node', 1);
// Fetch the number of times the invitation with ID 1 was sent and viewed.
$statistics->fetchMultipleValues(
['nb_sent', 'nb_viewed'],
'invitation',
1
);
Supporting organizations:
Sponsored initial development
Project information
- Module categories: Integrations
- Created by krystalcode on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.