I think you can put your code in an HMTL tag on pageview event (with more priority than page view tag).
If this doesn’t work, maybe try to access the Tracker object: Matomo.getTracker( trackerUrl, siteId ) then:
addDownloadExtensions( string | array ) - Specify additional file extensions to be recognized as downloads. Example: ‘doc’ or [‘doc’, ‘xls’]
removeDownloadExtensions( string | array ) - Specify file extensions to be removed from the list of download file extensions. Example: ‘doc’ or [‘doc’, ‘xls’]