From 2111ba8ffb754874075b5060e54dd7a8cdaf9bed Mon Sep 17 00:00:00 2001 From: Eliezer Steinbock <3090527+elie222@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:26:06 +0200 Subject: [PATCH] add loops ab test id --- packages/loops/src/loops.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/loops/src/loops.ts b/packages/loops/src/loops.ts index 5d3f3ac47..b504b96b9 100644 --- a/packages/loops/src/loops.ts +++ b/packages/loops/src/loops.ts @@ -22,7 +22,12 @@ export async function createContact( }> { const loops = getLoopsClient(); if (!loops) return { success: false }; - const resp = await loops.createContact(email, firstName ? { firstName } : {}); + // so we can run a/b tests with 2-6 groups easily + const abTestId = getRandomInt(60); + const resp = await loops.createContact( + email, + firstName ? { firstName, abTestId } : { abTestId }, + ); return resp; } @@ -62,3 +67,7 @@ export async function cancelledPremium( }); return resp; } + +function getRandomInt(max: number) { + return Math.ceil(Math.random() * max); +}