Documentation Functions Adding Custom File Extensions in Download Tracker
Adding Custom File Extensions in Download Tracker
By default, Data Plus allows you to track downloads of specific file types. However, if you need to track additional file types, you can easily add custom file extensions using the provided filter hook.
Adding Custom File Extensions
To add custom file extensions, you can directly handle the logic within the wpstatistics_data_plus_event_file_extensions
filter.
For example, to track additional file types such as .epub
, .apk
, .iso
, etc., you can use the following code snippet in your theme’s functions.php
file or in a custom plugin.
add_filter('wpstatistics_data_plus_event_file_extensions', function($fileExtensions) {
// Define your custom extensions
$customExtensions = [
'epub', // eBooks
'mobi', // eBooks
'apk', // Android apps
'iso', // Disc images
'dmg', // macOS disk images
'tar', // Archive files
'xz' // Compressed archives
];
// Merge custom extensions with the existing ones
return array_merge($fileExtensions, $customExtensions);
});