imce_download_tracker
Overview
The IMCE Download Tracker module provides comprehensive file download tracking and analytics within the IMCE file manager. It displays download count badges next to file names and offers detailed statistics through an intuitive modal interface.
Key Features
- Download Tracking: Automatically tracks file downloads using Drupal's
hook_file_download()(private files only) - Visual Badges: Shows download counts as blue badges next to file names with "Downloads: X" format
- Real-time Updates: Download badges refresh automatically when navigating folders
- Detailed Statistics: Tracks first download, last download, and download count for each file
- User Tracking: Records which user downloaded each file
- Modal Statistics View: View detailed download statistics in a responsive modal window
- Permission Control: Configurable permissions for accessing download statistics
- Clean Architecture: Well-organized, maintainable code structure
- Drush Commands: Built-in Drush commands for managing and troubleshooting download statistics
Important Limitations
File Download Tracking:
- Private Files: Download tracking works for files stored in private file system (
private://) - Public Files: Download tracking does NOT work for files stored in public file system (
public://) due to web server serving them directly - Workaround: To track public file downloads, consider using JavaScript click tracking or URL rewriting
Installation
- Install the module via Composer:
composer require drupal/imce_download_tracker - Enable the module:
drush en imce_download_tracker -y - Configure IMCE permissions: Go to Admin > Configuration > Media > IMCE and add the "Access download statistics" permission to your IMCE profiles
Usage
For Users
- View Download Badges: Download count badges appear next to file names in IMCE showing "Downloads: X"
- Automatic Updates: Badges update automatically when you navigate between folders
- View Detailed Statistics: Select one or more files in IMCE and click the "Download Statistics" button in the toolbar
For Administrators
- Configure Permissions: Go to Admin > Configuration > Media > IMCE and configure the "Access download statistics" permission
- Database Schema: The module creates a
file_download_statstable with download tracking data - Drush Management: Use built-in Drush commands for managing download statistics
Drush Commands
This module provides several Drush commands for managing and troubleshooting download statistics:
- Recount Statistics:
drush imce-download-tracker:recount- Recalculate download statistics for all files - Reset File Count:
drush imce-download-tracker:reset [fid]- Reset the download count for a specific file by its file ID - View Statistics:
drush imce-download-tracker:stats [--all] [--top=N]- Display download statistics for files
Examples:
drush imce-download-tracker:stats --top=10- Show top 10 most downloaded filesdrush imce-download-tracker:reset 123- Reset download count for file ID 123drush list | grep imce-download-tracker- List all available commands
Technical Details
Database Schema
The module creates a file_download_stats table with the following fields:
id: Primary keyfid: File ID from file_managed tablefilename: The filenameuri: The file URIdownload_count: Number of times downloadedfirst_download: Timestamp of first downloadlast_download: Timestamp of last downloaddownloaded_by: User ID who last downloaded the file
JavaScript Architecture
The module is organized into logical sections:
- INITIALIZATION: Setup and initialization functions
- UTILITY FUNCTIONS: Helper functions and utilities
- EVENT HANDLERS: Event management
- STATISTICS DISPLAY: Modal and statistics display
- BADGE MANAGEMENT: Badge creation and management
Requirements
- Drupal 9, 10, or 11
- IMCE module
- File module
- User module
Support
For issues and feature requests, please create an issue in the project repository. The module includes comprehensive logging for troubleshooting download tracking issues.
Contributing
Contributions are welcome! Please follow Drupal coding standards and create proper patches or pull requests.