
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
nuxt-ab-segment
Advanced tools
NuxtJS module for A/B testing with Segment Analytics
url?abs_experiment-x=1 or this.$abtest('experiment-x', true, true, 1);this.$abtest('experiment-x', true, false);this.$abtest('experiment-x', false);abs_disabled=1), which is useful for E2E tests in CI/CD pipelinesnuxt-ab-segment dependency to your project:npm install nuxt-ab-segment
nuxt-ab-segment module and configuration to nuxt.config.js:export default {
// ...other config options
modules: ["nuxt-ab-segment"];
abSegment: {
event: "AB Test", // optional
experiments: '~/experiments.js', // optional
debug: process.env.NODE_ENV !== 'production', // optional
}
}
experiments.js in project's root with an array of your experiments. An example:/**
* {
* name: string; A name to identify the experiment on this.$abtest('NAME_HERE')
* maxAgeDays: number; Number of days to persist the cookie of user's active variant
* variants: number[] | Experiment[]; An array of variant weights or an array of nested experiments.
* }
*/
module.exports = [
{
name: "experiment-x",
maxAgeDays: 15,
variants: [50, 50],
},
{
name: "experiment-y", // Weights will be automatically calculated [50, 50]
maxAgeDays: 15,
variants: [
{
name: "parent-1", // Weights will be automatically calculated [34, 33, 33]
maxAgeDays: 15,
variants: [
{
name: "children-1",
maxAgeDays: 15,
variants: [50, 50],
},
{
name: "children-2",
maxAgeDays: 15,
variants: [50, 50],
},
{
name: "children-3",
maxAgeDays: 15,
variants: [50, 50],
},
],
},
{
name: "parent-2",
maxAgeDays: 15,
variants: [50, 50],
},
],
},
];
nuxt-ab-segment to the types section of tsconfig.json:{
"compilerOptions": {
"types": ["nuxt-ab-segment"]
}
}
eventStringAB TestEvent name reported to Segment.
experimentsString~/experiments.jsFile path for your experiments definition.
debugBooleantruefalseEnables or disables printing Segment reports to the console.
It can be used inside components like:
{
data: () => ({
payBtnLabel: null as string | null,
}),
mounted() {
// Scenario: Determine an experiment variant and display a label accordingly.
const expA = this.$abtest('experiment-a');
if (expA === 0) {
this.payBtnLabel = 'Place order';
} else {
this.payBtnLabel = 'Pay now!';
}
// Scenario: Force a specific variant programmatically.
const expB = this.$abtest('experiment-b', { forceVariant: 1 });
console.log('Variant for expB is always 1');
// Scenario: Assign a variant and report it for analytics.
const expC = this.$abtest('experiment-c', { reportVariant: true });
console.log(`Variant for expC is ${expC}, and it was reported.`);
// Scenario: Avoid activating an A/B test at a specific step.
// (No variant assignment or reporting is done.)
const expD = this.$abtest('experiment-d', { assignVariant: false });
console.log('Variant for expD is always 0');
// Scenario: Report analytics and append specific properties.
// (experiment, but additional data is sent.)
const expE = this.$abtest('experiment-e', { reportVariant: true, segment: { properties: { device: 'mobile' } } });
console.log(`Variant for expE is ${expE}, and will include the properties: { experiment: 'experiment-e', variant: ${expE}, device: 'mobile' }`);
}
}
An example of event properties reported to Segment:
{
experiment: 'experiment-x',
variant: 1
}
weightedRandom()See the LICENSE file for license rights and limitations (MIT).
FAQs
NuxtJS module for A/B testing with Segment Analytics
We found that nuxt-ab-segment demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.

Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.

Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.