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);
});
Let’s get started
Take your business to next level

Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.