You mean you only want to use redirect for the "open in new tab" function? Not when clicking the image? This would require creating your own contextmenu item (see this post), link it to your own file.php
, which triggers your internal count mechanism and serves the file. This is not as effective as serving the file directly of course.
Opening a modal preview doesn't trigger any loading at all, because there is nothing to load. It just shows information. You can't trigger an external redirect load if there is no loading triggered from Files gallery.
This seems a bit unreasonable. Why not just use Google Analytics, which can automatically track various clicks?