Email Campaign A/B Testing

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

A/B Testing Email Campaigns

A/B testing email is sending different versions of an email to different audience segments to determine which variant yields better open and click rates. You can test subject lines, preview text, content, CTAs, and send time.

What to Test

  • Subject line — highest impact, directly affects open rate
  • Prehead/Preview text — displayed next to the subject in inbox
  • CTA button — text, color, position
  • Hero image — product photo vs illustration vs no image
  • Personalization — with user name vs without
  • Send time — morning vs evening, weekday vs weekend

Backend A/B Test Implementation

interface ABTestVariant {
  id: 'A' | 'B' | 'C';
  subject: string;
  templateId: string;
  weight: number;  // traffic share, e.g., 0.5 for 50/50
}

interface ABTest {
  id: string;
  campaignId: string;
  variants: ABTestVariant[];
  winnerMetric: 'open_rate' | 'click_rate';
  sampleSize: number;       // how many to send for testing
  winnerSendAt?: Date;      // when to send winner to remainder
}

async function sendABTest(test: ABTest, users: User[]) {
  // Shuffle users randomly
  const shuffled = users.sort(() => Math.random() - 0.5);

  // Split into groups according to weights
  let offset = 0;
  for (const variant of test.variants) {
    const count = Math.floor(test.sampleSize * variant.weight);
    const group = shuffled.slice(offset, offset + count);
    offset += count;

    await Promise.allSettled(
      group.map(user =>
        sendVariantEmail(user, variant, test.id)
      )
    );
  }

  // Save test information
  await db.abTests.create(test);

  // Schedule winner determination
  if (test.winnerSendAt) {
    await scheduleWinnerSelection(test.id, test.winnerSendAt);
  }
}

async function sendVariantEmail(user: User, variant: ABTestVariant, testId: string) {
  const html = await renderTemplate(variant.templateId, { user });
  const emailLogId = await sendEmail({
    to: user.email,
    subject: variant.subject,
    html,
  });

  await db.abTestParticipants.create({
    testId,
    variantId: variant.id,
    userId: user.id,
    emailLogId,
  });
}

Determining the Winner

async function determineWinner(testId: string): Promise<'A' | 'B' | 'C'> {
  const test = await db.abTests.findById(testId);

  const stats = await db.query<{
    variant_id: string;
    sent: number;
    opened: number;
    clicked: number;
  }>(`
    SELECT
      p.variant_id,
      COUNT(DISTINCT p.id) AS sent,
      COUNT(DISTINCT oe.email_log_id) AS opened,
      COUNT(DISTINCT ce.email_log_id) AS clicked
    FROM ab_test_participants p
    LEFT JOIN email_open_events oe ON oe.email_log_id = p.email_log_id
    LEFT JOIN email_click_events ce ON ce.email_log_id = p.email_log_id
    WHERE p.test_id = $1
    GROUP BY p.variant_id
  `, [testId]);

  const withRates = stats.map(s => ({
    ...s,
    open_rate: s.opened / s.sent,
    click_rate: s.clicked / s.sent,
  }));

  // Check statistical significance (z-test for proportions)
  const winner = withRates.reduce((best, current) => {
    const metric = test.winnerMetric === 'open_rate' ? 'open_rate' : 'click_rate';
    return current[metric] > best[metric] ? current : best;
  });

  return winner.variant_id as 'A' | 'B' | 'C';
}

// Send winner to remaining users
async function sendWinnerToRemainder(testId: string) {
  const winnerId = await determineWinner(testId);
  const test = await db.abTests.findById(testId);
  const winnerVariant = test.variants.find(v => v.id === winnerId)!;

  // Users who didn't participate in test
  const participantIds = await db.abTestParticipants.getUserIdsByTest(testId);
  const remainderUsers = await db.users.findExcluding(participantIds, test.campaignId);

  await Promise.allSettled(
    remainderUsers.map(user =>
      sendVariantEmail(user, winnerVariant, testId)
    )
  );
}

Statistical Significance

It's important not to declare a winner too early. Minimum sample size for 95% confidence with expected 25% open rate and 5% delta is about 1,200 recipients per variant. Online calculators (Optimizely, Evan Miller) are used for calculation.

function isStatisticallySignificant(
  controlConverted: number,
  controlTotal: number,
  variantConverted: number,
  variantTotal: number,
  confidenceLevel: number = 0.95
): boolean {
  const p1 = controlConverted / controlTotal;
  const p2 = variantConverted / variantTotal;
  const pPool = (controlConverted + variantConverted) / (controlTotal + variantTotal);
  const se = Math.sqrt(pPool * (1 - pPool) * (1/controlTotal + 1/variantTotal));
  const z = Math.abs(p2 - p1) / se;
  const zThreshold = confidenceLevel === 0.95 ? 1.96 : 2.576;  // 95% or 99%
  return z >= zThreshold;
}

Timeline

An A/B testing system with traffic split, metric collection, winner determination, and remainder send takes 3–5 days.