[Translate] A/b test for AngularJS templates

Source: Internet
Author: User

Editor's note: This article translates from Andrei Bondarev's "A/B testing your AngularJS Templates" published on Medium, Andrei is an engineer, lifelong learner.

If you want to do A/B testing on a single page application template, it is important to create a clean and extensible solution, rather than using conditional language to make the template more confusing, so:

A clean alternative is to create a separate template for each variable, which makes it easier to manage and track specific errors for variables.

In this case, we use Rails in the backend, and the framework uses split to drive the experiment. At the initial extract, our API controller returns the value of the variable by setting the value of the variable to the response header file called "X-variant":

We will create an interceptor to capture this variable value from the HTPP response of the Angular code. The interceptor will see if the variable header exists and pass it to the service that stores the variable value:

Variantservice will simply encapsulate any key-value pairs that we pass to it:

We divide the Sign_up_form.haml into two separate templates:

Now our form instruction will get the template according to the variant value of Variantservice:

Instead of specifying the template or Templateurl in the definition of the directive, it is requested and compiled in the link function. The implementation of this method is written here https://jellekralt.com/2015/08/13/dynamically-load-a-templateurl-in-an-angular-directive/, the core code is as follows:

Now, for the initial data load request to the server, the API returns a variable value that determines which template is rendered (Sign_up_form_a.haml or Sign_up_form_b.haml).

Note: The sample code follows John Papa's style guide: https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md

This article by Zoran @ Yell Technology compiled, the original link: https://medium.com/@rushing_andrei/ A-b-testing-your-angularjs-templates-part-1-6b7e93f97074#.s7khy1ard

[Translate] A/b test for AngularJS templates

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.