On the backend, I have Nest.js + PostgreSQL, and the only problem that needs to be solved is views for posts. I've been trying to find some information on Google and YouTube for a few days, but I haven't found anything useful, and I couldn't find any implementation examples either.
On the frontend, we send a request to api/posts/:id. Maybe we need to send a request to the Google API: ga-dev-tools.google/ga4/query-explorer/ and save the views, but when and what will trigger this "saving"?
Sending a request to the Google API every time is bad idea I think; it will likely interfere with caching in Nest.js (@UseInterceptors(CacheInterceptor)).
No, you don't send a request on every hit. You don't even connect storing pageviews to active sessions, unless you wanna have an independed parallel tracking, which your web server kinda already does for you in the access logs.
Otherwise, generally 2 options.
You store them with about 2-day delay, having a batch daily download script downloading all the hits from 2 days before, then you should have an ETL process in place where you stitch the limited API data responses into a fuller picture in your DB.
You do all that but with Google's internal tools and exporting all that raw data directly to BQ. No coding required. Now, getting that data from BQ to anywhere you want is a lot easier.
The second option requires so mmuch less dev time, that it's now become a default for exporting data from GA4. Only GA4 though.