Add analytics sampling - #98
Conversation
|
@smithjw1 As part of the work in #97 to update the latest supported WordPress version, it'd be great if we could also include analytics sampling as you suggested in #96. This adds a super simple sampling technique based on the current time that should remove 90% of our current analytics calls, while still leaving a "heartbeat" of usage metrics during sampling seconds. Let me know what you think! |
| $epoch_time = floor( microtime( true ) ); | ||
|
|
||
| if ( ( $epoch_time % 10 ) === 0 ) { | ||
| // Sample results. Only send analytics on 10% of configuration loads. |
There was a problem hiding this comment.
So microtime returns seconds, so this will send when the editor is loaded and it happens to be 0, 10, 20, etc.
I'm a little more concerned about this undercounting than the Block Data API, which when in high use is called almost constantly.
But we can check it out. The median number of MC stat hits for October has 348 so we would expect it to be 35 going forward, that still leaves enough room to notice changes.
But we should test that assumption after launch to see if the stats drop by more than 90 percent.
There was a problem hiding this comment.
Thank you, Jacob! You're right this this is a little more risky, but I think we're still covered statistically if the editor is being used more than a handful of times per day. From my basic math, if an editor is opened 20 times in a day, we have an 88% chance of registering a data point (1-((1-.1)^20)). If it goes up to 50 times (1-((1-.1)^50)), we're 99% likely to catch a point. This will affect sites where the editor is opened infrequently like a test site, but for any "enterprise" level of usage it should be noticeable and logged.
Description
See #96. Load analytics are recorded for VIP sites on each governance configuration load, which happens when the WordPress editor is opened. This amount of data isn't necessary and can have a small effect on editor load time.
This PR adds time-based sampling to usage analytics to reduce the number of analytics calls by 90%.
Steps to Test
Analytics::record_usage()call to determine when analytics would normally fire.( $epoch_time % 10 ) === 0.