{"id":16788207,"url":"https://github.com/nkoehring/vue-a2b","last_synced_at":"2025-03-17T03:30:19.132Z","repository":{"id":42662849,"uuid":"94876189","full_name":"nkoehring/vue-a2b","owner":"nkoehring","description":"Split Testing for Vue.js","archived":false,"fork":false,"pushed_at":"2023-01-06T11:18:18.000Z","size":957,"stargazers_count":87,"open_issues_count":13,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-29T03:14:34.020Z","etag":null,"topics":["ab-testing","split-testing","vue"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nkoehring.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-20T09:52:11.000Z","updated_at":"2024-01-29T17:43:58.000Z","dependencies_parsed_at":"2023-02-05T23:15:31.791Z","dependency_job_id":null,"html_url":"https://github.com/nkoehring/vue-a2b","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkoehring%2Fvue-a2b","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkoehring%2Fvue-a2b/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkoehring%2Fvue-a2b/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkoehring%2Fvue-a2b/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nkoehring","download_url":"https://codeload.github.com/nkoehring/vue-a2b/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841203,"owners_count":20356441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ab-testing","split-testing","vue"],"created_at":"2024-10-13T08:17:14.149Z","updated_at":"2025-03-17T03:30:18.765Z","avatar_url":"https://github.com/nkoehring.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vue-a2b\n\n\u003e split testing for Vuejs\n\n## Usage\n\nAdd the package to your project:\n\n``` bash\nyarn add vue-a2b\n# or\nnpm install vue-a2b\n```\n\n…and register it to Vue:\n\n``` js\nimport VueAB from 'vue-a2b'\nVue.use(VueAB)\n```\n\n*vue-a2b* uses [named slots](https://vuejs.org/v2/guide/components.html#Named-Slots) for defining test variations.\nAny amount of variations is supported (A/B/n). The the variation identifier should be used as slot name and can be any valid string.\nSelection chances are given as ratio. In the first example, **test A** has twice the chance to be selected over **test B**:\n\n    Note: Selection chances are parsed as whole numbers, so instead of 2.5 and 1 use 5 and 2.\n\n### minimal example\n\n``` html\n\u003ctemplate\u003e\n  \u003csplit-test\u003e\n    \u003ccomponent slot=\"A\" chance=\"2\" /\u003e\n    \u003ccomponent slot=\"B\" chance=\"1\" /\u003e\n  \u003c/split-test\u003e\n\u003c/template\u003e\n```\n\n### more examples\n\nChances are optional. If left out, every test gets the same chance to be picked.\nThe selection can also be forced with the *always* parameter, which is useful for testing:\n\n``` html\n\u003ctemplate\u003e\n  \u003csplit-test always=\"B\"\u003e \u003c!-- will always choose B, no matter the chances --\u003e\n    \u003ccomponent slot=\"A\" chance=\"2\" /\u003e\n    \u003ccomponent slot=\"B\" chance=\"1\" /\u003e\n  \u003c/split-test\u003e\n\u003c/template\u003e\n```\n\nIf more than one element is part of the test, use template tags:\n\n``` html\n\u003ctemplate\u003e\n  \u003csplit-test\u003e\n    \u003ctemplate slot=\"A\" chance=\"2\"\u003e\n      \u003cbutton\u003ehello\u003c/button\u003e\n      \u003cbutton\u003eWorld\u003c/button\u003e\n    \u003c/template\u003e\n    \u003ctemplate slot=\"B\" chance=\"1\"\u003e\n      \u003cbutton\u003ehey ho\u003c/button\u003e\n      \u003cbutton\u003elets go\u003c/button\u003e\n    \u003c/template\u003e\n  \u003c/split-test\u003e\n\u003c/template\u003e\n```\n\n## functional usage\n\nSince version `0.2` functional usage is supported. The component scope now has the `$abtest` method. It can be used to initialize an A/B test without the `\u003csplit-test\u003e` component or to get the test value:\n\nTo initialize a new test, `created()` is a good spot:\n``` js\nexport default {\n  created () {\n    // creates a test 'fancy-bubbles' with 75% chance for even more bubbles\n    this.$abtest('fancy-bubbles', { bubbles: 25, lotsOfBubbles: 75 })\n  }\n}\n```\n\nTo get a value, for example in data, just call `$abtest` again:\n``` js\nexport default {\n  data () {\n    return {\n      more_bubbles: this.$abtest('fancy-bubbles') === 'lotsOfBubbles'\n    }\n  }\n}\n```\n\nThe function is reachable for the template as well:\n\n```html\n\u003ctemplate\u003e\n  \u003cdiv :class='$abtest(\"fancy-bubbles\")'\u003ebubbles!\u003c/div\u003e\n\u003c/template\u003e\n\n\u003cstyle\u003e\n.lotsOfBubbles {\n  font-size: var(--extra-big);\n}\n\u003c/style\u003e\n```\n\n### outside of components\n\n`vue-a2b` exports the abtest method among others, so it is possible to access it via:\n\n```js\nimport { abtest } from 'vue-a2b'\n```\n\nAdditionally `randomCandidate` is exported, which allows to get a randomly picked sample out of a list of VNodes or an object:\n\n```\nimport { randomCandidate } from 'vue-a2b'\n\n// pics a random candidate foo, bar, baz with 75%, 20%, 5% chance respectively\nconst candidate = randomCandidate({\n  foo: 75,\n  bar: 20,\n  baz: 5\n})\n```\n\n## Settings\n\n### Test name\n\nThe test name needs to be set with the name attribute. If no name is given,\nit might be deferred from the parent components name attribute.\n\n``` html\n\u003ctemplate\u003e\n  \u003csplit-test name=\"the-one-test\"\u003e\n    \u003ccomponent slot=\"A\" chance=\"2\" /\u003e\n    \u003ccomponent slot=\"B\" chance=\"1\" /\u003e\n  \u003c/split-test\u003e\n\u003c/template\u003e\n```\n\n    Attention: Test name is mandatory!\n\n### Storage options\n\nYou can set storage method, name and expiry on initialization. Supported methods are `cookie` (the default) and `localStorage`.\n\n``` js\nVue.use(VueAB, {\n  storage: {\n    method: 'localStorage',\n    name: 'project42'\n  }\n})\n```\n\nThe stored value expires after 30 days by default. This can be changed:\n\n``` js\nVue.use(VueAB, {\n  storage: {\n    method: 'cookie',\n    expiry: 7 // one week until the cookie expires\n  }\n})\n```\n\n    Note: LocalStorage doesn't support expiration by default but the entries get\n    a timestamp and old entries will be ignored to make expiration possible.\n\n    Note: The expiry date is refreshed with every page visit. The entry only\n    expires, if the user doesn't come back in the specified time.\n\n### Component Name\n\nBy default `\u003csplit-test\u003e` is the component that wraps a new test. This name can be overwritten on initialization:\n\n``` js\nVue.use(VueAB, {component: 'a-b'})\n```\n``` html\n\u003ctemplate\u003e\n  \u003ca-b\u003e\n    \u003c!-- variants --\u003e\n  \u003c/a-b\u003e\n\u003c/template\u003e\n```\n\n## Build setup\n\nWe recommend to use [yarn](https://yarnpkg.com) but [npm](https://www.npmjs.com/) works too:\n\n``` bash\n# Install dependencies\nyarn install\n# or\nnpm install\n\n# Build for production with minification\nyarn build\n# or\nnpm run build\n```\n\n## License\n\nMIT © fromAtoB GmbH\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkoehring%2Fvue-a2b","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnkoehring%2Fvue-a2b","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkoehring%2Fvue-a2b/lists"}