├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── examples
├── browser
│ └── index.html
└── node
│ └── basic.js
├── package.json
├── sixpack.js
└── test
└── sixpack-test.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Node
2 | node_modules
3 |
4 | # Log files
5 | *.log
6 |
7 | *~
8 | *#*
9 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /node_modules/
3 | /test/
4 | /.gitignore
5 | /.npmignore
6 | /npm-debug.log
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, SeatGeek, Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 |
6 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 |
8 | Neither the name of the SeatGeek nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # sixpack-client
2 |
3 | Node / browser client library for SeatGeek's [Sixpack](https://github.com/seatgeek/sixpack) A/B testing framework.
4 |
5 | ## Installation
6 |
7 | Include the "sixpack.js" script. The `sixpack` object will be added to your environment. In the browser do the following:
8 |
9 | ``` html
10 |
11 | ```
12 |
13 | If you're using sixpack-client with node.js start by installing it with [npm](https://www.npmjs.com):
14 |
15 | ```sh
16 | npm install sixpack-client
17 | ```
18 |
19 | then require the "sixpack-client" module:
20 |
21 | ``` javascript
22 | var sixpack = require('sixpack-client');
23 | ```
24 |
25 | ## Usage
26 |
27 | Check out the examples in the `examples` directory for some quick examples for how to use the library. Here's a very basic example in node:
28 |
29 | ```js
30 | var sixpack = require('sixpack-client');
31 |
32 | var session = new sixpack.Session();
33 | session.participate('test-exp', ['alt-one', 'alt-two'], function (err, res) {
34 | if (err) throw err;
35 | alt = res.alternative.name
36 | if (alt == 'alt-one') {
37 | console.log('default: ' + alt);
38 | } else {
39 | console.log(alt);
40 | }
41 | });
42 | ```
43 |
44 | When instantiating the session object you can pass optional params `client_id`, `base_url`, `ip_address`, `user_agent`
45 |
46 | ```js
47 | var sixpack = new sixpack.Session({
48 | client_id: 12345,
49 | base_url: 'http://google.com/sixpack',
50 | ip_address: '1.2.2.1',
51 | user_agent: 'ChromeBot'
52 | });
53 | ```
54 |
55 | Client ID is a previously generated client id that you've previously stored. IP Address and User Agent are used for bot detection.
56 |
57 | ### Options
58 |
59 | A number of options can be passed to a sixpack `session`. A few are highlighted below.
60 |
61 | - `base_url`. Base URL of the sixpack-server.
62 | - `client_id`. ID of the specific client.
63 | - `ignore_alternates_warning`. Allow sixpack-js to send a `participate` request which contains no alternates.
64 | - `timeout`. Number of milliseconds to wait for a response from sixpack-server before returning a timeout response.
65 |
66 | ### Forcing an Alternative
67 |
68 | For debugging / design work it can be useful to force a page to load
69 | using a specific alternative. To force an alternative use the `force`
70 | parameter to `participate()`. If you're using sixpack.js in the
71 | browser you can also just include a query parameter,
72 | e.g. `/your-page?sixpack-force-EXPERIMENT_NAME=ALTERNATIVE_NAME`.
73 |
74 | ## Tests
75 |
76 | A number of _end-to-end_ tests are located in `./test/sixpack-test.js`. They use [mocha](https://mochajs.org) as the testing framework and [chai](http://chaijs.com) as the assertion library, and require a running [sixpack-server](https://github.com/seatgeek/sixpack#getting-started).
77 |
78 | Run the tests with:
79 | ```sh
80 | npm run test
81 | ```
82 |
83 | ### Sixpack server location
84 |
85 | The tests assume the [sixpack-server](https://github.com/seatgeek/sixpack) server is running and located at `http://localhost:5000`. To use a different location, _e.g._ for a Docker [container](https://github.com/ainoya/docker-sixpack), run tests with the following pattern:
86 | ```sh
87 | SIXPACK_BASE_URL=http://docker:5000 npm run test
88 | ```
89 |
90 | ## Contributing
91 |
92 | 1. Fork it
93 | 2. Create your feature branch (`git checkout -b my-new-feature`)
94 | 3. Write and run tests with `npm test` (see [Tests](#tests) above for more information)
95 | 4. Commit your changes (`git commit -am 'Added some feature'`)
96 | 5. Push to the branch (`git push -u origin my-new-feature`)
97 | 6. Create new pull request
98 |
--------------------------------------------------------------------------------
/examples/browser/index.html:
--------------------------------------------------------------------------------
1 |
2 |