A flexible WordPress plugin that tracks file downloads with multiple tracking methods. Perfect for monitoring PDF downloads and other attachment files.
- Multiple Tracking Methods: Choose from three different tracking approaches
- Download Analytics: Track download counts for WordPress attachments
- Media Library Integration: View download counts directly in the WordPress media library
- Admin Dashboard: Easy configuration through WordPress admin settings
- Secure Downloads: Files are served through WordPress with proper security checks
- Performance Optimized: Uses X-Sendfile/X-Accel-Redirect for efficient file serving
- Upload the
trackerfolder to your/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Settings > Tracker to configure your preferred tracking method
The plugin offers three different tracking methods to suit various needs:
- How it works: Uses JavaScript to detect PDF link clicks and track them via AJAX
- Best for: Sites where you want minimal server-side processing
- Pros: Lightweight, works with external files
- Cons: Requires JavaScript enabled, may miss some downloads
- How it works: Intercepts post content and replaces PDF links with tracking endpoints
- Best for: Sites with content-heavy pages containing many PDF links
- Pros: Reliable tracking, works without JavaScript
- Cons: Processes content on every page load
- How it works: Intercepts
wp_get_attachment_url()to redirect through tracking endpoint - Best for: Sites that primarily use WordPress attachment URLs
- Pros: Most efficient, minimal overhead
- Cons: Only works with WordPress attachments
- Navigate to Settings > Tracker in your WordPress admin
- Select your preferred tracking method
- Save changes
The plugin will automatically flush rewrite rules when you change tracking methods.
Once activated and configured, the plugin automatically:
- Tracks downloads of PDF files and other attachments
- Increments download counters
- Serves files through secure endpoints
- Go to Media > Library in WordPress admin
- Download counts are displayed in a dedicated column
- Counts are shown as blue badges next to each file
Files are served through tracking endpoints like:
https://yoursite.com/download-file/?id=123
tracker/
├── tracker.php # Main plugin file
├── classes/
│ ├── class-admin.php # Admin interface and settings
│ ├── class-base-tracker.php # Base class with common functionality
│ ├── class-content-buffer.php # Content buffer tracking method
│ ├── class-js-tracking.php # JavaScript tracking method
│ └── class-attachment-url-hook.php # URL hook tracking method
└── README.md # This file
- Download counts are stored as post meta (
download_count) - External file downloads are stored in WordPress options table
- No additional database tables required
- Nonce verification for AJAX requests
- File existence validation before serving
- Attachment ID validation
- Proper MIME type detection
- X-Sendfile support for Apache
- X-Accel-Redirect support for Nginx
- Efficient file serving with proper headers
- Minimal database queries
- WordPress 4.0 or higher
- PHP 7.0 or higher
- jQuery (for JS tracking method)
- All modern browsers
- JavaScript tracking method requires JavaScript enabled
- Other methods work without JavaScript
- Check that your selected tracking method is active
- Verify that files are WordPress attachments (for URL hook method)
- Ensure JavaScript is enabled (for JS tracking method)
- Check WordPress error logs for any issues
If download URLs return 404 errors:
- Go to Settings > Permalinks
- Click "Save Changes" to flush rewrite rules
- Or change tracking method and change it back
- Use the "Attachment URL Hook" method for best performance
- Ensure your server supports X-Sendfile or X-Accel-Redirect
- Consider caching if using content buffer method
The plugin uses an abstract base class (Tracker_Base) that can be extended to create custom tracking methods:
class Custom_Tracker extends Tracker_Base {
protected function init_tracking() {
// Your custom tracking logic
}
}tracker_tracking_method- Filter the tracking method optiontracker_download_count- Filter download count before savingtracker_file_serve- Filter file serving behavior
- Initial release
- Three tracking methods implemented
- Admin interface with settings
- Media library integration
- Download count tracking
For support, feature requests, or bug reports, please contact the plugin developer.
This plugin is licensed under the GPL v2 or later.
Note: This plugin is designed for WordPress sites and requires proper WordPress installation and configuration to function correctly.