Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Ask for a review after the first finalized poll and split business asks between Capterra and G2 (#3526)
Luke Vellac4a8e45c417e
diff --git a/apps/web/src/env.ts b/apps/web/src/env.tsindex 20f5692e7..0f7149642 100644--- a/apps/web/src/env.ts+++ b/apps/web/src/env.ts@@ -114,13 +114,6 @@ export const env = createEnv({GOOGLE_CLIENT_ID: z.string().optional(),GOOGLE_CLIENT_SECRET: z.string().optional(),- /**- * Review site the post-finalize review request sends business users to.- * Users on a free mail provider are sent to Trustpilot instead.- */- REVIEW_REQUEST_BUSINESS_SITE: z- .enum(["capterra", "g2"])- .default("capterra"),/*** Conferencing integrations (Google Meet, Zoom, Microsoft Teams, Webex).* The flag needs at least one provider's OAuth app configured; see@@ -325,7 +318,6 @@ export const env = createEnv({LICENSE_API_AUTH_TOKEN: process.env.LICENSE_API_AUTH_TOKEN,GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,- REVIEW_REQUEST_BUSINESS_SITE: process.env.REVIEW_REQUEST_BUSINESS_SITE,CONFERENCING_ENABLED: process.env.CONFERENCING_ENABLED,ZOOM_CLIENT_ID: process.env.ZOOM_CLIENT_ID,ZOOM_CLIENT_SECRET: process.env.ZOOM_CLIENT_SECRET,diff --git a/apps/web/src/features/review-request/constants.ts b/apps/web/src/features/review-request/constants.tsindex 01dea704a..b813ec8de 100644--- a/apps/web/src/features/review-request/constants.ts+++ b/apps/web/src/features/review-request/constants.ts@@ -8,9 +8,8 @@ export const isReviewRequestEnabled = !isSelfHosted;// finalize click, short enough that the booking is still freshexport const reviewRequestEmailDelayMs = 60 * 60_000;-// Consumers review on Trustpilot; business users on one B2B site at a time,-// because splitting a few reviews a week across sites leaves each too thin for-// its badges. REVIEW_REQUEST_BUSINESS_SITE picks the B2B site.+// Consumers review on Trustpilot; business users are split evenly across the+// B2B sitesexport const reviewSites = {trustpilot: {name: "Trustpilot",@@ -25,7 +24,8 @@ export const reviewSites = {},g2: {name: "G2",- url: "https://www.g2.com/products/rallly/review_modalities/new?utm_source=rallly&utm_medium=email&utm_campaign=review-request",+ // G2's vendor review link, so reviews are attributed to our invitation+ url: "https://www.g2.com/contributor/cloud-2e719343-1982-403e-8985-699b7a393863",},} as const;diff --git a/apps/web/src/features/review-request/mutations.ts b/apps/web/src/features/review-request/mutations.tsindex 2979842f7..d0b268558 100644--- a/apps/web/src/features/review-request/mutations.ts+++ b/apps/web/src/features/review-request/mutations.ts@@ -96,8 +96,8 @@ const failWith = (message: string) => () => new QueuedEmailFailed({ message });/*** Sends the review request email queued by `queueReviewRequest`. The subject- * is the user. The site is picked at send time, so a change to- * REVIEW_REQUEST_BUSINESS_SITE applies to emails already queued.+ * is the user. The site is picked at send time, so a change to the routing+ * applies to emails already queued.*/export const sendReviewRequest = Effect.fn("reviewRequest.sendReviewRequest")(function* ({ subjectId }: { id: string; subjectId: string }) {@@ -112,10 +112,7 @@ export const sendReviewRequest = Effect.fn("reviewRequest.sendReviewRequest")(return yield* new QueuedEmailSkipped({ reason: "User is banned" });}- const site = pickReviewSite({- email: user.email,- businessSite: env.REVIEW_REQUEST_BUSINESS_SITE,- });+ const site = pickReviewSite({ userId: subjectId, email: user.email });const branding = yield* Effect.tryPromise({try: () => getInstanceBranding(),catch: failWith("Failed to load branding"),diff --git a/apps/web/src/features/review-request/utils.test.ts b/apps/web/src/features/review-request/utils.test.tsindex e18faa60e..8ecb3288c 100644--- a/apps/web/src/features/review-request/utils.test.ts+++ b/apps/web/src/features/review-request/utils.test.ts@@ -7,24 +7,15 @@ import {} from "./utils";describe("isEligibleForReviewRequest", () => {- it("asks on the second finalized poll with three participants", () => {+ it("asks on the first finalized poll with three participants", () => {expect(isEligibleForReviewRequest({- finalizedPollCount: 2,+ finalizedPollCount: 1,participantCount: 3,}),).toBe(true);});- it("does not ask on the first finalized poll", () => {- expect(- isEligibleForReviewRequest({- finalizedPollCount: 1,- participantCount: 10,- }),- ).toBe(false);- });-it("does not ask when fewer than three people responded", () => {expect(isEligibleForReviewRequest({@@ -37,27 +28,37 @@ describe("isEligibleForReviewRequest", () => {describe("pickReviewSite", () => {it("sends free mail addresses to Trustpilot", () => {- expect(- pickReviewSite({ email: "[email protected]", businessSite: "capterra" }),- ).toBe("trustpilot");+ expect(pickReviewSite({ userId: "user-1", email: "[email protected]" })).toBe(+ "trustpilot",+ );});- it("sends company addresses to the business site", () => {- expect(- pickReviewSite({ email: "[email protected]", businessSite: "capterra" }),- ).toBe("capterra");- expect(- pickReviewSite({ email: "[email protected]", businessSite: "g2" }),- ).toBe("g2");+ it("splits company addresses evenly across the business sites", () => {+ const counts = { capterra: 0, g2: 0, trustpilot: 0 };+ for (let i = 0; i < 1000; i++) {+ counts[+ pickReviewSite({ userId: `user-${i}`, email: "[email protected]" })+ ]++;+ }+ expect(counts.trustpilot).toBe(0);+ expect(counts.capterra).toBeGreaterThan(400);+ expect(counts.g2).toBeGreaterThan(400);+ });++ it("always picks the same business site for a user", () => {+ const site = pickReviewSite({ userId: "user-1", email: "[email protected]" });+ expect(pickReviewSite({ userId: "user-1", email: "[email protected]" })).toBe(+ site,+ );});it("does not treat a subdomain of a free mail provider as consumer", () => {expect(pickReviewSite({+ userId: "user-1",email: "[email protected]",- businessSite: "g2",}),- ).toBe("g2");+ ).not.toBe("trustpilot");});});diff --git a/apps/web/src/features/review-request/utils.ts b/apps/web/src/features/review-request/utils.tsindex c63c3149c..562b5af5d 100644--- a/apps/web/src/features/review-request/utils.ts+++ b/apps/web/src/features/review-request/utils.ts@@ -1,8 +1,13 @@-import type { BusinessReviewSite, ReviewSite } from "./constants";-import { consumerEmailDomains, reviewSites } from "./constants";+import type { ReviewSite } from "./constants";+import {+ businessReviewSites,+ consumerEmailDomains,+ reviewSites,+} from "./constants";-// One finalized poll can be a fluke; a second one means Rallly worked for them-const minFinalizedPolls = 2;+// A finalized poll with a group behind it means Rallly worked for them.+// Waiting for a second one asked a fifth as many people.+const minFinalizedPolls = 1;// Filters out solo tests: the poll worked for a groupconst minParticipants = 3;@@ -20,20 +25,35 @@ export function isEligibleForReviewRequest({}/**- * Consumers are pointed to Trustpilot, everyone else to the business review- * site, judged by whether the address is on a free mail provider.+ * Consumers are pointed to Trustpilot, judged by whether the address is on a+ * free mail provider. Everyone else is split evenly across the business review+ * sites by user id, so a retried email points to the same site.*/export function pickReviewSite({+ userId,email,- businessSite,}: {+ userId: string;email: string;- businessSite: BusinessReviewSite;-}) {+}): ReviewSite {const domain = email.trim().toLowerCase().split("@").pop();- return domain && consumerEmailDomains.has(domain)- ? ("trustpilot" as const)- : businessSite;+ if (domain && consumerEmailDomains.has(domain)) {+ return "trustpilot";+ }+ return (+ businessReviewSites[hashString(userId) % businessReviewSites.length] ??+ businessReviewSites[0]+ );+}++// FNV-1a: stable across runtimes, spreads ids evenly+function hashString(value: string) {+ let hash = 0x811c9dc5;+ for (let i = 0; i < value.length; i++) {+ hash ^= value.charCodeAt(i);+ hash = Math.imul(hash, 0x01000193);+ }+ return hash >>> 0;}/**diff --git a/packages/emails/locales/en/emails.json b/packages/emails/locales/en/emails.jsonindex 3bb316937..d8193c64d 100644--- a/packages/emails/locales/en/emails.json+++ b/packages/emails/locales/en/emails.json@@ -107,7 +107,7 @@"reviewRequest_greeting": "Hi {firstName},","reviewRequest_greetingNoName": "Hi there,","reviewRequest_guidelines": "Reviews must follow the <a>{siteName} community guidelines</a>.",- "reviewRequest_intro": "I saw you just scheduled another meeting with Rallly. I hope it saved you some back-and-forth.",+ "reviewRequest_intro": "I saw you just scheduled a meeting with Rallly. I hope it saved you some back-and-forth.","reviewRequest_preview": "Would you leave a quick review of Rallly on {siteName}?","reviewRequest_reply": "Good, bad or somewhere in between, an honest review helps. And if something about Rallly is getting in your way, just reply. I read every reply.","reviewRequest_subject": "A small favour?",diff --git a/packages/emails/src/templates/review-request.tsx b/packages/emails/src/templates/review-request.tsxindex a8bd37f87..d0a56544c 100644--- a/packages/emails/src/templates/review-request.tsx+++ b/packages/emails/src/templates/review-request.tsx@@ -66,7 +66,7 @@ async function ReviewRequestEmail({<Text>{t("reviewRequest_intro", {defaultValue:- "I saw you just scheduled another meeting with Rallly. I hope it saved you some back-and-forth.",+ "I saw you just scheduled a meeting with Rallly. I hope it saved you some back-and-forth.",})}</Text><Text>diff --git a/turbo.json b/turbo.jsonindex ba756d14e..609a09510 100644--- a/turbo.json+++ b/turbo.json@@ -100,7 +100,6 @@"PORT","RATE_LIMIT_ENABLED","QUICK_CREATE_ENABLED",- "REVIEW_REQUEST_BUSINESS_SITE","S3_ACCESS_KEY_ID","S3_BUCKET_NAME","S3_ENDPOINT",