trailguide 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +95 -5
- data/lib/trail_guide/experiments/base.rb +1 -0
- data/lib/trail_guide/experiments/participant.rb +1 -0
- data/lib/trail_guide/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: bcb676051862d84d744bf4a84c60adcd1ccba36b0cf319bc3c37c2f3ae774a0e
         | 
| 4 | 
            +
              data.tar.gz: 7397a453afdef82edc8ced81f1a54b342324aaf508adcc5d159e0efb2bb958a0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fd5fdd35dd59f7fe8ea812c08d6773850ab0d9acec0a1a20da5d55db3f690bd43ea7aa11126d0a78408059fdef7940fec78504a43ae6d82caac897e11f75bcf0
         | 
| 7 | 
            +
              data.tar.gz: 5042d43b78c5ef826854627308632e6db970d755963bc6c7c96e10060ea0ea0f09f42f6b6c0462c38845a708afc3456312cc412b8b513995ba2caa834d698127
         | 
    
        data/README.md
    CHANGED
    
    | @@ -590,24 +590,114 @@ If you're using a custom adapter, you'll need to make sure that your adapter is | |
| 590 590 |  | 
| 591 591 | 
             
            ## JavaScript Client
         | 
| 592 592 |  | 
| 593 | 
            -
            There is a simple javascript client available that mimics the ruby usage as closely as possible, and is ready to be used with the rails asset pipeline. This client uses axios to hit the API, and requires that you mount it in your routes.
         | 
| 593 | 
            +
            There is a simple javascript client available that mimics the ruby usage as closely as possible, and is ready to be used with the rails asset pipeline or via webpack. This client uses axios to hit the API, and requires that you mount it in your routes.
         | 
| 594 | 
            +
             | 
| 595 | 
            +
            ```ruby
         | 
| 596 | 
            +
            # config/routes.rb
         | 
| 597 | 
            +
             | 
| 598 | 
            +
            Rails.application.routes.draw do
         | 
| 599 | 
            +
             | 
| 600 | 
            +
              mount TrailGuide::Engine => 'api/experiments'
         | 
| 601 | 
            +
             | 
| 602 | 
            +
              # ...
         | 
| 603 | 
            +
            end
         | 
| 604 | 
            +
            ```
         | 
| 605 | 
            +
             | 
| 606 | 
            +
            ### Rails Asset Pipeline
         | 
| 607 | 
            +
             | 
| 608 | 
            +
            If you're using the rails asset pipeline, just require trailguide in your `application.js` and instantiate a client.
         | 
| 594 609 |  | 
| 595 610 | 
             
            ```javascript
         | 
| 596 | 
            -
            // require the trailguide client in your application.js or wherever makes sense
         | 
| 611 | 
            +
            // require the trailguide client in your application.js or wherever makes sense for your project
         | 
| 597 612 | 
             
            //= require trailguide
         | 
| 598 613 |  | 
| 599 614 | 
             
            // create a client instance
         | 
| 600 615 | 
             
            // make sure to pass in the route path where you've mounted the trailguide engine
         | 
| 601 616 | 
             
            var client = TrailGuide.client('/api/experiments');
         | 
| 617 | 
            +
            ```
         | 
| 618 | 
            +
             | 
| 619 | 
            +
            The client is just a wrapper around `axios`, so you can provide any of their [request configuration options](https://github.com/axios/axios#request-config).
         | 
| 620 | 
            +
             | 
| 621 | 
            +
            ```javascript
         | 
| 622 | 
            +
            var client = TrailGuide.client({
         | 
| 623 | 
            +
              baseURL: '/api/experiments',
         | 
| 624 | 
            +
              headers: {...},
         | 
| 625 | 
            +
              transformRequest: (data,headers) => (...)
         | 
| 626 | 
            +
            });
         | 
| 627 | 
            +
            ```
         | 
| 628 | 
            +
             | 
| 629 | 
            +
            ### Webpack
         | 
| 630 | 
            +
             | 
| 631 | 
            +
            If you're using webpack, you can install the corresponding `trailguide` npm package with `yarn` or `npm`:
         | 
| 632 | 
            +
             | 
| 633 | 
            +
            ```
         | 
| 634 | 
            +
            yarn add trailguide
         | 
| 635 | 
            +
            ```
         | 
| 636 | 
            +
             | 
| 637 | 
            +
            ```
         | 
| 638 | 
            +
            npm install trailguide
         | 
| 639 | 
            +
            ```
         | 
| 602 640 |  | 
| 641 | 
            +
            Then use it in your project:
         | 
| 642 | 
            +
             | 
| 643 | 
            +
            ```javascript
         | 
| 644 | 
            +
            import { client } from 'trailguide'
         | 
| 645 | 
            +
             | 
| 646 | 
            +
            // create a client instance
         | 
| 647 | 
            +
            // make sure to pass in the route path where you've mounted the trailguide engine
         | 
| 648 | 
            +
            export default client('/api/experiments')
         | 
| 649 | 
            +
            ```
         | 
| 650 | 
            +
             | 
| 651 | 
            +
            ```javascript
         | 
| 652 | 
            +
            var TrailGuide = require('trailguide');
         | 
| 653 | 
            +
             | 
| 654 | 
            +
            module.exports = {
         | 
| 655 | 
            +
              // create a client instance
         | 
| 656 | 
            +
              // make sure to pass in the route path where you've mounted the trailguide engine
         | 
| 657 | 
            +
              client: TrailGuide.client('/api/experiments')
         | 
| 658 | 
            +
            };
         | 
| 659 | 
            +
            ```
         | 
| 660 | 
            +
             | 
| 661 | 
            +
            The client is just a wrapper around `axios`, so you can provide any of their [request configuration options](https://github.com/axios/axios#request-config).
         | 
| 662 | 
            +
             | 
| 663 | 
            +
            ```javascript
         | 
| 664 | 
            +
            client({
         | 
| 665 | 
            +
              baseURL: '/api/experiments',
         | 
| 666 | 
            +
              headers: {...},
         | 
| 667 | 
            +
              transformRequest: (data,headers) => (...)
         | 
| 668 | 
            +
            })
         | 
| 669 | 
            +
            ```
         | 
| 670 | 
            +
             | 
| 671 | 
            +
            ### Usage
         | 
| 672 | 
            +
             | 
| 673 | 
            +
            Once you have a handle on a client, the usage is the same. All methods return a promise with the `response` as a payload.
         | 
| 674 | 
            +
             | 
| 675 | 
            +
            ```javascript
         | 
| 603 676 | 
             
            // enroll in an experiment
         | 
| 604 | 
            -
            client.choose('experiment_name') | 
| 677 | 
            +
            client.choose('experiment_name', {...optional_metadata...}).then(response => {
         | 
| 678 | 
            +
             // response.data will be:
         | 
| 679 | 
            +
             // { experiment: "experiment_name", variant: "assigned_variant_name", metadata: {...} }
         | 
| 680 | 
            +
            })
         | 
| 605 681 |  | 
| 606 682 | 
             
            // convert for an experiment with an optional goal
         | 
| 607 | 
            -
            client.convert('experiment_name', 'optional_goal') | 
| 683 | 
            +
            client.convert('experiment_name', 'optional_goal', {...optional_metadata...}).then(response => {
         | 
| 684 | 
            +
              // response.data will be:
         | 
| 685 | 
            +
              // { experiment: "experiment_name", checkpoint: "optional_goal", metadata: {...} }
         | 
| 686 | 
            +
            })
         | 
| 608 687 |  | 
| 609 688 | 
             
            // return the participant's active experiments and their assigned variant group
         | 
| 610 | 
            -
            client.active() | 
| 689 | 
            +
            client.active().then(response => {
         | 
| 690 | 
            +
              // response.data will be:
         | 
| 691 | 
            +
              // { experiments: { experiment_name: "assigned_variant_name" } }
         | 
| 692 | 
            +
            })
         | 
| 693 | 
            +
            ```
         | 
| 694 | 
            +
             | 
| 695 | 
            +
            The client is just a wrapper around `axios`, and all the client methods support any of their [request configuration options](https://github.com/axios/axios#request-config) as the last argument.
         | 
| 696 | 
            +
             | 
| 697 | 
            +
            ```javascript
         | 
| 698 | 
            +
            client.active({ headers: {...}, transformRequest: (data,headers) => (...) }).then(...)
         | 
| 699 | 
            +
            client.choose('experiment_name', {...optional_metadata...}, { headers: {...}, transformRequest: (data,headers) => (...) }).then(...)
         | 
| 700 | 
            +
            client.convert('experiment_name', 'optional_goal', {...optional_metadata...}, { headers: {...}, transformRequest: (data,headers) => (...) }).then(...)
         | 
| 611 701 | 
             
            ```
         | 
| 612 702 |  | 
| 613 703 | 
             
            ## Conversion Goals
         | 
| @@ -71,6 +71,7 @@ module TrailGuide | |
| 71 71 | 
             
                    :storage_key, :combined?, :start_manually?, :reset_manually?,
         | 
| 72 72 | 
             
                    :allow_multiple_conversions?, :allow_multiple_goals?, :is_combined?,
         | 
| 73 73 | 
             
                    :enable_calibration?, :track_winner_conversions?, :callbacks, to: :class
         | 
| 74 | 
            +
                  delegate :context, to: :participant
         | 
| 74 75 |  | 
| 75 76 | 
             
                  def initialize(participant)
         | 
| 76 77 | 
             
                    @participant = Experiments::Participant.new(self, participant)
         | 
    
        data/lib/trail_guide/version.rb
    CHANGED