I want to perform A/B testing on my widget. The widget is a simple javascript solution, the client include a script (loader.js) on its page, loader.js then loads necessary scripts and css which replaces a target div with new content. All files for the widget is hosted on my site.
I want to measure clicks on a button for different layouts. Been looking at google analytics experiments. What I'm trying to find is a solution for how to get the statistics when its not just page1 and page2. How do I divide the traffic? Do I have to build a solution that divides traffic to widget1.js and widget2.js from my loader.js and then use a virtual url? Is it even possible to perform A/B testing with google experiments with this solution? The A/B testing tools I've been looking at does not seem to work with this type of solution.
Would appreciate any tips that can push me in the right direction.
You should have a look at the javascript API for content experiments () which allow experiments whithout redirects. See the linked article on how to set up the experiment in the interface (basically you insert dummy urls as variations).
Load the content experiment library:
<script src="//www.google-analytics.com/cx/api.js?experiment=YOUR_EXPERIMENT_ID"></script>
then use cxApi.chooseVariation();
to get a number for a variation (will return the same number for returning visitors) and load an according version of your widget.
If all is implemented correctly the selected variation will be transmitted at the GA pageview call.