Can we batch requests to GA?
benlk opened this issue · 2 comments
Rather than firing a new GA request every single time the tracking image is called, can we instead batch those requests to, say, once per minute or once per hour?
We'd need to have a way to temporarily track the hit-tracking information in the database, though, and because it's something we need to keep, we can't use the Transients API to do so, since the Transients API says we can't assume that the data in the transient will exist. https://codex.wordpress.org/Transients_API
I wonder if we could just expand on this functionality that saves each hit to the relevant post
We could use that and every minute/hour/x fire a job that fires off the request to GA.
We're sending more than the bare number of hits to GA, however:
Could we write a function for https://codex.wordpress.org/Function_Reference/wp_schedule_single_event ? That would at least get the HTTP ping loop out of the reply to the visitor.
Based on https://developer.wordpress.org/reference/classes/WP_Http/request/ it looks like we may be able to pass a 'blocking' => false
argument as part of the wp_remote_post( $url, $args )
args array, so that the server doesn't wait for the response contents.