humanmade / altis-analytics

Analytics module for Altis
https://www.altis-dxp.com/resources/docs/analytics/
GNU General Public License v3.0
9 stars 3 forks source link

Add ability to preview different A/B test block variants #194

Closed rmccue closed 2 years ago

rmccue commented 2 years ago

As a marketer, I want to be able to preview what my different A/B test variants are for a block in line so that I can see what they look like in context.

This should be a block level control.

Acceptance criteria:

rmccue commented 2 years ago

@rmccue to sketch a potential design for this.

robindevitt commented 2 years ago

@rmccue Do you have a sketch for this?

yumito commented 2 years ago

Linking you to the guid sketch from Ryan on the epic ticket https://app.zenhub.com/workspaces/altis-5c378365e15075539771e4e3/issues/humanmade/product-dev/812

robindevitt commented 2 years ago

Slack thread for some questions and communication around this task as I have been getting through it : https://hmn.slack.com/archives/C5WSNGC9F/p1638362120249900

  1. Is there a need for a user to individually preview a single variant through a link when the user would be able to use the tabs on the front end when previewing the post? The link currently that I have in place. Should it link directly to a specific A/B Test Variant? Screenshot 2021-12-03 at 17.18.33.png Given when viewing the variant you will see these: Screenshot 2021-12-02 at 14.20.47.png

  2. If page/post has multiple A/B test blocks on it, should they be able to preview all of the A/B test blocks on the page?

  3. Currently a single variant is displayed through the render_block function. For the user to preview the different variants, could should the render_block be adjusted above to render all of the variants and the tabs to toggle between them? Essentially on when the user has edit permission will the "render_all_block"(eg) show else the render_block is used.

roborourke commented 2 years ago

Is there a need for a user to individually preview a single variant through a link when the user would be able to use the tabs on the front end when previewing the post?

Not necessarily, though it's a quick and easy option. If it's proving to be too much of a pain then move on to just doing the tabs.

If page/post has multiple A/B test blocks on it, should they be able to preview all of the A/B test blocks on the page?

Yep.

Currently a single variant is displayed through the render_block function. For the user to preview the different variants, could should the render_block be adjusted above to render all of the variants and the tabs to toggle between them? Essentially on when the user has edit permission will the "render_all_block"(eg) show else the render_block is used.

Not quite - the primary block web component is rendered e.g. <ab-test-block ...></ab-test-block> and then each variant is rendered as a <template>.

For a logged in user with appropriate permissions previewing the post you could output some additional UI above the <ab-test-block>, or replace it altogether, then write the JS to handle clicks on the tabs to clone the target template content into a display div eg.

if ( is_preview() ) {
   return sprintf( '%s<div class="ab-test-xb-preview" data-client-id="%s"><div class="ab-test-xb-preview__tabs"></div><div class="ab-test-xb-preview__content"></div></div>', $inner_content, $client_id );
}

and some JS like:

document.querySelectorAll( '.ab-test-xb-preview' ).forEach( function ( xb ) {
   var templates = document.querySelectorAll( 'template[data-parent-id="' + xb.dataset.clientId + '"]' );
   // for each template add a tab button to the tabs div
   // add a click handler for each to set the content divs content by cloning the chosen template content
   // trigger click on the first tab to get initial default content
} );

I just pseudo-coded the last bit with comments but hopefully that makes some sense.

robindevitt commented 2 years ago

Thanks Rob this made a huge help and gave some direction to getting the content. I am currently getting an unstyled version of the tabs working.

robindevitt commented 2 years ago

I have updated my PR with some further WIP changes. I currently have the content of the tabs and tabs rendering on the front end when previewing the page. Working on getting the tabs and content linked.

robindevitt commented 2 years ago

I have made some progress on this and just need to sort out one "bug" I discovered late today.

Should have it ready for review tomorrow.

PR has been updated.

robindevitt commented 2 years ago

This has been completed and the PR has been merged.