if the files you want to track are exposed e.g via Resource you could subscribe to the \mod_resource\event\course_module_viewed event via a local plugin, to write your own logging system e.g. file (https://docs.moodle.org/dev/Event_2).
Otherwise, that event could be read via https://docs.moodle.org/dev/Logging_2, mainly from the [mdl_]logstore_standard_log table but it should be better to pass through its public API.
Did you already think at an external system for analytics like Piwik?
See an example in https://github.com/gjb2048/moodle-theme_essential/blob/8c78520999950a0e6f00a1189a7fce88e3ef3acb/layout/tiles/piwik.php#L74.