Problem/Motivation
Querying today's and even yesterday's statistics are no use because GA4 reports 0 until 24 hours passed from the page view count. It means reliable statistics can only be obtained after 2 days have passed at least. It could be a major headache to get the proper view count for those who don't query pageviews for all nodes, but only for a few created in the last X days, or from a recent time period.
Steps to reproduce
This will take a while to reproduce:
1. use GTM or GA4 code to count every page visit
2. create a node with /first-article alias, make a few page visits, for example 3
3. create a node with /second-article alias, make a few page visits, for example 2
4. go to GA4, in the real time data, you'll see 1 user with 5 page_view events
5. in GA4 event statistics for Today, there won't be any data
6. in my testing 12 hours later still no page_views.
7. in my testing 16 hours later, I see that /first-article has 3 but no /second-article page_views.
8. in my testing 24 hours later, I see that /first-article has 3 and /second-article has 2 page_views.
Proposed resolution
This means GA4 may not give final results of pageviews for Today and Yesterday because it is still in calculating and processing that. What you get are partial results. So, we should only query the past no newer than 2 days ago to avoid getting stale results. Now, you can set that in the query using "Custom days ago". But we will need one for the nodes, too.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork google_analytics_counter-3370551
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kaszarobertComment #5
kaszarobert