You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There was some recent discussion around page level A/B testing (swapping out the template depending on the variant) using edge rewrites. We came to the conclusion that whilst this is possible without modifications to Gatsby core it would be nice to provide some sort of API to allow for this in the createPage action. Similar to the Script component, having a recommended way to handle this will ensure better community direction and less fragmentation. First class Gatsby Cloud support would also be amazing!
There's been some similar discussions around this:
It's still unclear how the API would work but during the createPage call, to do this currently, you need to use matchPath to set the expected path for the template. eg.
Because these two pages have the same matchPath they will both be selected for use at / but the first one takes precedent so we have to swap the page-data.json files out. Similar to the defer API, if the user was allowed to pass a percentage for the chance the variant would be shown I think that would feel very comprehensive. eg.
However, without knowing what affinity the user is expecting it's hard for Gatsby to do anything for us here (ie. should we use cookies to persist the test session? should we use a session token?)
Perhaps this affinity is configured in gatsby-config similar to trailingSlash or other global settings:
{pageVariantAffinity: 'cookie'|'token'}
Finally, the API could provide some async function that would determine the A/B variant based on user data:
// maybe in `gatsby-node.ts`constselectUserVariant=async(userData: UserData): Variant=>{// determine variant based on user data ie.if(userData.cookies['test_bucket']==='a'){returnVariant.A}if(userData.cookies['test_bucket']==='b'){returnVariant.B}// or you could do an async call to your personalization engine to determine variantconstr=awaitfetch('https://mypersonalizationengine.com/api/v1/variant')// use response data to determine variant}
Drawbacks / alternatives
Perhaps the scope of A/B testing is beyond the touch of Gatsby. This will seriously complicate the internals of pages and will probably have implications on a lot of core functionality like routing, caching, etc.
Rollout
...
What's next?
Decide if this feature is worth adding and the added complexity is worth the gains
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
There was some recent discussion around page level A/B testing (swapping out the template depending on the variant) using edge rewrites. We came to the conclusion that whilst this is possible without modifications to Gatsby core it would be nice to provide some sort of API to allow for this in the
createPage
action. Similar to theScript
component, having a recommended way to handle this will ensure better community direction and less fragmentation. First class Gatsby Cloud support would also be amazing!There's been some similar discussions around this:
I have also written an article on our discussion here https://daviddisch.com/blog/using-netlify-edge-functions-for-request-rewrites-to-run-page-level-a-b-tests-on-a-gatsby-site
Detailed design
It's still unclear how the API would work but during the
createPage
call, to do this currently, you need to usematchPath
to set the expected path for the template. eg.Because these two pages have the same
matchPath
they will both be selected for use at/
but the first one takes precedent so we have to swap thepage-data.json
files out. Similar to thedefer
API, if the user was allowed to pass a percentage for the chance the variant would be shown I think that would feel very comprehensive. eg.However, without knowing what affinity the user is expecting it's hard for Gatsby to do anything for us here (ie. should we use cookies to persist the test session? should we use a session token?)
Perhaps this affinity is configured in
gatsby-config
similar totrailingSlash
or other global settings:Finally, the API could provide some async function that would determine the A/B variant based on user data:
Drawbacks / alternatives
Perhaps the scope of A/B testing is beyond the touch of Gatsby. This will seriously complicate the internals of pages and will probably have implications on a lot of core functionality like routing, caching, etc.
Rollout
...
What's next?
Beta Was this translation helpful? Give feedback.
All reactions