OllieMackJames Posted September 12, 2018 Share Posted September 12, 2018 Thanks to @Zeka for helping out. I am not a coder and had to tinker some to make it work, but hey it works! The code below allows splittesting 2 pages against each other. Visitors will be divided in 2 groups based on their IP. Measuring clicks to be done via analytics software. Concern might be lack of speed of loading, because this can not be cached, I have no data yet regarding loss of speed of delivery of pages, but will check. This is the code that does the trick: function visitorgroup($which = null) { $ip = wire('session')->getIP(); $int = ip2long($ip); $group = ($int % 2) ? 'a' : 'b'; if(is_null($which)) return $group; return $group == $which; } if(visitorgroup('b')): if($page->id == 1 && $page->page2use4homepage) { $page = $page->page2use4homepage;} endif; if($page->id == 1 && $page->page2use4homepage) { $page = $page->page2use4splittest;} Here's what I would like to do: - divide traffic over 2 versions of a page - measure clicks on a call to action button to see which page gives a better conversion. I already have a system in place to pull data from a different underlying page into one page, I do it with this code: if($page->id == 1 && $page->page2use4homepage) { $page = $page->page2use4homepage; The code above allows me to change a page while keeping the original intact, I went this route because I found on one of my sites after changing a page, I lost rankings in google, and needed a way to change a page, and with one click go back to the original. But now I want to use this dynamic in a different way for splittesting conversions on one page. Let me write down what I would like to happen in the code above: if($page->id == 1 && $page->page2use4homepage) { function count CallToActionClicks for each of the options below count clicks on CallToAction button; function dividetraffic for 50% of the traffic present $page = $page->page2use4homepage version 1; for the other 50% of the traffic present $page = $page->page2use4homepage version 2; Any ideas much appreciated, thanks! Link to comment Share on other sites More sharing options...
Zeka Posted September 12, 2018 Share Posted September 12, 2018 @OllieMackJames Measure clicks to "Call to action" buttons you can by using Google Analytics Events. There an example of simple A\B testing plugin from Kirby's forum https://getkirby.com/docs/cookbook/a-b-testing. It would be easy to rewrite it for Processwire. If you want to do some kind of AB testing than you should also take care of returned visitors as they should see the same version of the page that they saw on the first visit. 4 Link to comment Share on other sites More sharing options...
OllieMackJames Posted September 12, 2018 Author Share Posted September 12, 2018 @zeka, thanks for that! Analytics route for CallToAction measurement, makes good sense, thanks getkirby splittest plugin looks good, I wonder how to port this to Processwire. I copied the code below from https://getkirby.com/docs/cookbook/a-b-testing. Question now is... How can I turn it into Processwire language and then make into a plugin?: function visitorgroup($which = null) { $ip = visitor::ip(); $int = ip2long($ip); $group = ($int % 2) ? 'a' : 'b'; if(is_null($which)) return $group; return $group == $which; } Then if that works I would add something like this to the template: if($page->id == 1 && $page->page2use4homepage) { if(visitorgroup('a')): $page = $page->page2use4homepageoption1; elseif: $page = $page->page2use4homepageoption2; Any ideas how to do this? Thanks Link to comment Share on other sites More sharing options...
Zeka Posted September 12, 2018 Share Posted September 12, 2018 function visitorgroup($which = null) { $ip = wire('session')->getIP(); $int = ip2long($ip); $group = ($int % 2) ? 'a' : 'b'; if(is_null($which)) return $group; return $group == $which; } if($page->id == 1 && $page->page2use4homepage) { if(visitorgroup('a')): $page = $page->page2use4homepageoption1; elseif: $page = $page->page2use4homepageoption2; 1 Link to comment Share on other sites More sharing options...
Soma Posted September 12, 2018 Share Posted September 12, 2018 *moved to dev talk* 1 Link to comment Share on other sites More sharing options...
OllieMackJames Posted September 12, 2018 Author Share Posted September 12, 2018 @Zeka many thanks! Am now going to test this. @Soma moved, ok thanks Link to comment Share on other sites More sharing options...
OllieMackJames Posted September 12, 2018 Author Share Posted September 12, 2018 @Zeka just tested and the following does not seem to work: function visitorgroup($which = null) { $ip = wire('session')->getIP(); $int = ip2long($ip); $group = ($int % 2) ? 'a' : 'b'; if(is_null($which)) return $group; return $group == $which; } I have added the above code to my _funcs.php which is called in my template with: require_once "_funcs.php"; Then straight after that line, in the same template I add: if($page->id == 1 && $page->page2use4homepage) { if(visitorgroup('a')): $page = $page->page2use4homepage; elseif: $page = $page->page2use4splittest; But then I get this error Server Error We're sorry! The server encountered an internal error and was unable to complete your request. Please try again later. I also tested with all of your code in one go in my template, did not work either: function visitorgroup($which = null) { $ip = wire('session')->getIP(); $int = ip2long($ip); $group = ($int % 2) ? 'a' : 'b'; if(is_null($which)) return $group; return $group == $which; } if($page->id == 1 && $page->page2use4homepage) { if(visitorgroup('a')): $page = $page->page2use4splittest; elseif: $page = $page->page2use4homepage; Thanks! Link to comment Share on other sites More sharing options...
OllieMackJames Posted September 12, 2018 Author Share Posted September 12, 2018 OK, got it to work with the following code, don't know why, as I am not a coder, but hey it works, posting solution for anyone who wants to use it. Added following code to template function visitorgroup($which = null) { $ip = wire('session')->getIP(); $int = ip2long($ip); $group = ($int % 2) ? 'a' : 'b'; if(is_null($which)) return $group; return $group == $which; } if(visitorgroup('b')): if($page->id == 1 && $page->page2use4homepage) { $page = $page->page2use4homepage;} endif; if($page->id == 1 && $page->page2use4homepage) { $page = $page->page2use4splittest;} Link to comment Share on other sites More sharing options...
kongondo Posted May 26, 2020 Share Posted May 26, 2020 On 9/12/2018 at 8:42 AM, Zeka said: There an example of simple A\B testing plugin from Kirby's forum https://getkirby.com/docs/cookbook/a-b-testing. It would be easy to rewrite it for Processwire. Just a note that this link has moved here: https://getkirby.com/docs/cookbook/extensions/ab-testing Link to comment Share on other sites More sharing options...
Recommended Posts