A/B testing - loading different content files

How would I use A/B testing to load different content files, rather then different snippets or code? I’m using the Builder plugin so this is down to what’s in the content file more then visual style or loading different code.

To get this right: Do you want to compare content from different folders or rather content from different builder modules?

The entire page is controlled by builder. I have basically setup three zones in the template. Content, sidebar, and footer. These allow me to put things like Calls to action in the side bar or a big on in the footer. That means i have basically have only three page layouts, sidebar left & right and a wide content one.

So the page layout and where things like calls to action are is entirely driven by the panel through the builder plugin. So I essentially need to make the same page twice, and rearrange the layout in the panel, and potentially load a different style sheet.

My template looks like this…

<?= snippet('global/htmlhead', ['scripts' => false]) ?>

<?php if(!$page->showmenuinhero()->bool()): ?>
  <?= snippet('global/header') ?>
<?php endif ?>

<!-- HERO -->
<?= snippet('global/hero') ?>

<!-- CONTENT -->
<main id="middle">

<div class="sidebar sidebar-left">
<div class="main content">
  <?php foreach($page->contentbuilder()->toBuilderBlocks() as $block): ?>
    <?= snippet('blocks/' . $block->_key(), array('data' => $block)) ?>
  <?php endforeach ?>
</div>

<div class="flank">
  <?php foreach($page->sidebarbuilder()->toBuilderBlocks() as $block): ?>
    <?= snippet('blocks/' . $block->_key(), array('data' => $block)) ?>
  <?php endforeach ?>
</div>

</div>

<!-- BLOCKS -->
<div class="footer-blocks">
  <?php foreach($page->footerbuilder()->toBuilderBlocks() as $block): ?>
    <?= snippet('blocks/' . $block->_key(), array('data' => $block)) ?>
  <?php endforeach ?>
</div>

</main>

<!-- FOOTER -->
<?= snippet('global/footer', ['scripts' => true]) ?>

</body>
</html>

If you build two completely different pages, you either serve page A or B, e.g. via a route.

Sure, but how do i do that without effecting the URL? I cant have multiple content files in the same folder so i would nee to make /mysubpage/a and /mysitepage/b but those will be children and I want the URL to stay as /mysubpage.

And I need to know which one got served, since i will GA or something to track the page’s effectiveness.

Yes, that’s why I said a route to mysubpage that loads either A or B depending on visitor group.

I didnt since that as i was still typing a response :slight_smile: I think i need to check for the existance of the A & B subfolders in a route and return one of those, if not load the normal content.

Isn’t it pretty irrelevant which one got served, since you know/define who gets to see what and then in your Google analytics you will see which visitor group performed better.

I think it would be easier if A must exist and B is an option and the parent just a container for this type of setup?

But GA will just see visits to the same URL wont it? As far as its concerned its the same page, it doesnt know which group the visitor fell into. I was going to put stuff on the buttons so if they get click GA will track the button got clicked more times on version B of the page.

Yes, but if you define user groups A and B, e.g. by IP, then you can certainly see on Google dashboard how often visitor group A (with odd IP numbers) visited Page X and how often visitor group B (with even IP numbers) visited Page X (because that also implies that visitor group A got served version A of Page X, and visitor group B got served version B of Page X)?

Otherwise serving the same URL wouldn’t make sense at all, or you would have to add a tag to the URL.

Oh yes i see what you mean, that would give me more data to mull over. For now, i’m just trying to figure out the optimum places to put buttons that lead to new business enquiries, but going down to that detail might be useful in the future.

It doesn’t really matter what you do, if it’s just moving a button or serving completely different pages. As long as the criteria you use for your visitor groups are somehow filterable on Google analytics, you will be able to see the results and also know what you served to that group.

I’m trying this route, but it’s throwing a whoops… (trim() expects parameter 1 to be string, object given)

'routes' => [
      [
          'pattern' => '(:any)',
          'action'  => function () {
              if ($page = page($this)->find('b')) {
                  return page($page);
              } else {
                  return page($this);
              }
          }
      ]
  ],
'routes' => [
      [
          'pattern' => '(:any)',
          'action'  => function ($id) {
              if ($page = page($id)->find('b')) {
                  return page($page->id());
              } else {
                  return page($id);
              }
          }
      ]
  ],

Bingo :slight_smile: That did it. thanks.

In case it helps someone else, with the plugin setup as described in the cookbook guide, the route below with serve the correct page according to visitor group…

'routes' => [
  [
      'pattern' => '(:any)',
      'action'  => function ($id) {
      if (visitorgroup('a') === true) {
          return page($id);
        } else {
          if ($page = page($id)->find('b')) {
              return page($page->id());
          } else {
              return page($id);
            }
        }
      }
    ]
],