Hi friend,
I found an example of this method.
https://www.kavoir.com/2010/05/simplest-php-hit-counter-or-download-counter-count-the-number-of-times-of-access-visits-or-downloads.html
In the example it uses a txt file to store the counter number, but you can use an update_field ($ selector, $ value, [$ post_id]);
greetings
Hi friend,
Custom fields continue to work and are normally supported with Gutenberg.
Operation is the same with or without Gutenberg.
You can now use ACF PRO to create your own blocks, or use ACF in the normal way.
greetings
Hello Friend, how are you?
For you to count views or downloads of the pdf file, you need to change the workflow you have developed.
Today, you provide the user with the direct link to the file (pdf or otherwise), so you can’t know who clicked or not.
My suggestion to solve your problem, and first you create a template or a wp_ajax that receives by parameter the file that needs to be downloaded (or the post_id linked to the file).
This adds +1 to the preview field and then redirects the user to the final file link.