workbox icon indicating copy to clipboard operation
workbox copied to clipboard

Include builtin AB testing option

Open martinschierle opened this issue 6 years ago • 4 comments

Feature request:

Many websites find it hard to prove/measure the value of service worker caching and offline, and it's rare that it get split tested correctly.

I suggest to build AB testing into workbox (or maybe add as module). The suggested workflow would mean:

  • Developer can enable/disable AB testing in sw, and can control size of test (or maybe even a general holdback of x%)
  • For the testgroup all caching and routes in SW would become inactive, basically the sw disables itself
  • However, the workbox offline analytics module can still be active - it already has the option to override a given GA dimension - this can directly be used to flag the part of the split the user is in

This way a developer could easily enable an AB test on sw with just a flag (plus new custom dimension in GA) - and then see potential uplift in page metrics, user engagement etc. directly in GA

martinschierle avatar Apr 02 '20 20:04 martinschierle

This will be a helpful feature to gauge service worker benefits (even starting from a POC and getting buy in). Would like to see this in workbox

gswetha avatar Apr 06 '20 08:04 gswetha

Some thoughts about a hypothetical workbox-buckets module

  • I could imagine an const bucket = await getBucket{({bucketA: 4, bucketB: 1, ...}) etc. interface that would allow you to set up an arbitrary number of buckets with different relative weighted chances of joining each. If the current origin hasn't previously been assigned a bucket, that will pick one (bucketA has 4 times as many people as bucketB) and write the membership to IDB. If the current origin has previously been assigned one, it will return that membership from IDB.

  • An await assignBucket('bucketC') method could force a bucket assignment.

  • An await clearBucket() would clear out the IDB assignment.

  • You could then use the bucket value as you see fit, like:

if (bucket === 'bucketB') {
  precacheAndRoute(self.__WB_MANIFEST);
  registerRoute(...);
}

I like that flexibility to just include/remove logic based on thee current bucket identifier rather than some "magic" global switch that made registered routes inactive.

  • workbox-google-analytics's initialize() method currently takes in a GoogleAnalyticsInitializeOptions option, which assigns extra parameters to requests that are replayed after coming back online. It would be good to also allow it to take in parameters that get added in to all pings, even when online, which would represent bucket membership. That logic could theoretically be handled as part of the window client, not in the service worker, but it might just be cleaner to do it in the service worker. Something like:
const bucketParams = generateBucketParams(bucket);
// This interface would probably need to be cleaned up a bit.
initialize(googleAnalyticsInitializeOptions, googleAnalyticsBucketParams);

(Developers who are using something other than Google Analytics would be responsible for intercepting that platforms' pings and adding in the bucket parameters as needed.)

How does that all sound? Anything that it leaves out?

jeffposnick avatar Apr 08 '20 14:04 jeffposnick

Indeed much better than my initial suggestion ;-) Thanks a lot Jeff for thinking this through and drafting a possible solution! I would like that a lot, in fact there's just one really minor nitpick - I'm prefer a different naming than 'bucket' - maybe we can steal the phrasing from amp-experiment and call it 'treatment':

https://amp.dev/documentation/components/amp-experiment/

martinschierle avatar Apr 09 '20 12:04 martinschierle

Hi there,

Workbox is moving to a new engineering team within Google. As part of this move, we're declaring a partial bug bankruptcy to allow the new team to start fresh. We realize this isn't optimal, but realistically, this is the only way we see it working. For transparency, here're the criteria we applied:

Thanks, and we hope for your understanding! The Workbox team

tomayac avatar Apr 25 '24 08:04 tomayac