+ )}
+
{step === "about-you" && (
[];
+ /** Custom properties for this page's Plausible pageview and every later event on it. */
+ analyticsProps?: Record;
}
const {
@@ -37,6 +39,7 @@ const {
noindex = false,
hideDonatePopout = false,
schema = [],
+ analyticsProps = {},
} = Astro.props;
// /page and /page/ both resolve, so both must name the same no-slash canonical.
@@ -86,8 +89,15 @@ const structuredData = [organizationSchema(), ...schema];
+ {
+ Object.keys(analyticsProps).length > 0 && (
+
+ )
+ }
diff --git a/src/lib/heroPhotoAssignment.test.ts b/src/lib/heroPhotoAssignment.test.ts
new file mode 100644
index 00000000..38a74fc9
--- /dev/null
+++ b/src/lib/heroPhotoAssignment.test.ts
@@ -0,0 +1,67 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("./growthbookServer", () => ({
+ loadFeaturePayload: vi.fn(),
+ evalServerFeature: vi.fn(),
+}));
+vi.mock("./visitorAssignment", () => ({
+ requestAssignmentId: vi.fn(),
+}));
+
+const { loadFeaturePayload, evalServerFeature } = await import("./growthbookServer");
+const { requestAssignmentId } = await import("./visitorAssignment");
+const { assignHeroPhoto } = await import("./heroPhotoAssignment");
+
+describe("assignHeroPhoto", () => {
+ const locals = { runtime: { env: { PUBLIC_GROWTHBOOK_CLIENT_KEY: "sdk-test" } } };
+ const req = () => new Request("https://techforpalestine.org/");
+
+ beforeEach(() => {
+ vi.mocked(loadFeaturePayload).mockResolvedValue({ features: {} });
+ vi.mocked(requestAssignmentId).mockResolvedValue("visitor-id");
+ vi.mocked(evalServerFeature).mockReturnValue({
+ value: "laptops",
+ source: "experiment",
+ } as never);
+ });
+ afterEach(() => vi.clearAllMocks());
+
+ it("returns the variant GrowthBook assigned, evaluated on the assignment id", async () => {
+ expect(await assignHeroPhoto(req(), locals)).toBe("laptops");
+ expect(vi.mocked(evalServerFeature).mock.calls[0].slice(1)).toEqual([
+ "homepage-hero-photo",
+ "visitor-id",
+ ]);
+ });
+
+ it("returns null when the result is not from the experiment", async () => {
+ vi.mocked(evalServerFeature).mockReturnValue({ value: "laptops", source: "force" } as never);
+ expect(await assignHeroPhoto(req(), locals)).toBeNull();
+ });
+
+ it("returns null without a client key", async () => {
+ expect(await assignHeroPhoto(req(), {})).toBeNull();
+ expect(evalServerFeature).not.toHaveBeenCalled();
+ });
+
+ it("returns null when the payload is unavailable", async () => {
+ vi.mocked(loadFeaturePayload).mockResolvedValue(undefined);
+ expect(await assignHeroPhoto(req(), locals)).toBeNull();
+ });
+
+ it("returns null without an assignment id", async () => {
+ vi.mocked(requestAssignmentId).mockResolvedValue(null);
+ expect(await assignHeroPhoto(req(), locals)).toBeNull();
+ expect(evalServerFeature).not.toHaveBeenCalled();
+ });
+
+ it("returns null and logs when evaluation throws", async () => {
+ const spy = vi.spyOn(console, "error").mockImplementation(() => {});
+ vi.mocked(evalServerFeature).mockImplementation(() => {
+ throw new Error("boom");
+ });
+ expect(await assignHeroPhoto(req(), locals)).toBeNull();
+ expect(spy).toHaveBeenCalledWith("Hero photo assignment failed", expect.any(Error));
+ spy.mockRestore();
+ });
+});
diff --git a/src/lib/heroPhotoAssignment.ts b/src/lib/heroPhotoAssignment.ts
new file mode 100644
index 00000000..361e9f1f
--- /dev/null
+++ b/src/lib/heroPhotoAssignment.ts
@@ -0,0 +1,28 @@
+import { getEnv } from "../utils/getEnv";
+import {
+ HERO_PHOTO_EXPERIMENT,
+ type HeroPhotoVariant,
+ variantFromFeature,
+} from "../utils/heroPhotoExperiment";
+import { evalServerFeature, loadFeaturePayload } from "./growthbookServer";
+import { requestAssignmentId } from "./visitorAssignment";
+
+/** The hero photo variant GrowthBook assigns this visitor, or null when they are not in the
+ * test (flag off, CDN down, or no stable id). `now` is for tests. */
+export async function assignHeroPhoto(
+ request: Request,
+ locals: unknown,
+ now?: () => Date
+): Promise {
+ try {
+ const clientKey = getEnv("PUBLIC_GROWTHBOOK_CLIENT_KEY", locals);
+ const payload = clientKey ? await loadFeaturePayload(clientKey) : undefined;
+ if (!payload) return null;
+ const id = await requestAssignmentId(request, locals, now);
+ if (!id) return null;
+ return variantFromFeature(evalServerFeature(payload, HERO_PHOTO_EXPERIMENT, id));
+ } catch (error) {
+ console.error("Hero photo assignment failed", error);
+ return null;
+ }
+}
diff --git a/src/lib/heroPhotoSplit.test.ts b/src/lib/heroPhotoSplit.test.ts
new file mode 100644
index 00000000..ceb57894
--- /dev/null
+++ b/src/lib/heroPhotoSplit.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from "vitest";
+import { evalServerFeature } from "./growthbookServer";
+
+// No mocks: runs the real GrowthBook SDK to check the experiment rule shape splits evenly.
+describe("homepage-hero-photo split", () => {
+ const payload = {
+ features: {
+ "homepage-hero-photo": {
+ defaultValue: "control",
+ rules: [
+ {
+ key: "homepage-hero-photo",
+ variations: ["control", "speaker", "laptops", "stage"],
+ weights: [0.25, 0.25, 0.25, 0.25],
+ coverage: 1,
+ hashAttribute: "id",
+ },
+ ],
+ },
+ },
+ };
+
+ it("buckets every visitor into the experiment, about a quarter per variant", () => {
+ const total = 4000;
+ const counts: Record = {};
+ for (let i = 0; i < total; i++) {
+ const result = evalServerFeature(payload, "homepage-hero-photo", crypto.randomUUID());
+ expect(result.source).toBe("experiment");
+ const value = String(result.value);
+ counts[value] = (counts[value] ?? 0) + 1;
+ }
+ expect(Object.keys(counts).sort()).toEqual(["control", "laptops", "speaker", "stage"]);
+ for (const count of Object.values(counts)) {
+ expect(count / total).toBeGreaterThan(0.22);
+ expect(count / total).toBeLessThan(0.28);
+ }
+ });
+});
diff --git a/src/lib/navAssignment.test.ts b/src/lib/visitorAssignment.test.ts
similarity index 65%
rename from src/lib/navAssignment.test.ts
rename to src/lib/visitorAssignment.test.ts
index 557eb1ff..d570bd45 100644
--- a/src/lib/navAssignment.test.ts
+++ b/src/lib/visitorAssignment.test.ts
@@ -1,18 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-vi.mock("./growthbookServer", () => ({
- loadFeaturePayload: vi.fn(),
- evalServerFeature: vi.fn(),
-}));
-
-const { loadFeaturePayload, evalServerFeature } = await import("./growthbookServer");
-const {
- assignNavLabelVariant,
+import {
computeAssignmentId,
normalizeIp,
requestAssignmentId,
resetAssignmentWarning,
-} = await import("./navAssignment");
+} from "./visitorAssignment";
const base = {
secret: "test-secret",
@@ -94,35 +87,3 @@ describe("requestAssignmentId", () => {
expect(warn).toHaveBeenCalledOnce();
});
});
-
-describe("assignNavLabelVariant", () => {
- const env = { NAV_ASSIGNMENT_SECRET: "test-secret", PUBLIC_GROWTHBOOK_CLIENT_KEY: "sdk-test" };
- const locals = { runtime: { env } };
- const headers = { "cf-connecting-ip": base.ip, "user-agent": base.userAgent };
- const req = () => new Request("https://techforpalestine.org/", { headers });
- const now = () => base.date;
-
- beforeEach(() => {
- resetAssignmentWarning();
- vi.mocked(loadFeaturePayload).mockResolvedValue({ features: {} });
- vi.mocked(evalServerFeature).mockReturnValue({ value: "B", source: "force" } as never);
- });
- afterEach(() => vi.clearAllMocks());
-
- it("returns the variant GrowthBook assigned, evaluated on the daily id", async () => {
- expect(await assignNavLabelVariant(req(), locals, now)).toBe("B");
- expect(vi.mocked(evalServerFeature).mock.calls[0][2]).toBe(await computeAssignmentId(base));
- });
-
- it("is inactive without the secret: no assignment, GrowthBook is never asked", async () => {
- vi.spyOn(console, "warn").mockImplementation(() => {});
- const noSecret = { runtime: { env: { PUBLIC_GROWTHBOOK_CLIENT_KEY: "sdk-test" } } };
- expect(await assignNavLabelVariant(req(), noSecret, now)).toBeNull();
- expect(evalServerFeature).not.toHaveBeenCalled();
- });
-
- it("returns null when the GrowthBook payload is unavailable", async () => {
- vi.mocked(loadFeaturePayload).mockResolvedValue(undefined);
- expect(await assignNavLabelVariant(req(), locals, now)).toBeNull();
- });
-});
diff --git a/src/lib/navAssignment.ts b/src/lib/visitorAssignment.ts
similarity index 70%
rename from src/lib/navAssignment.ts
rename to src/lib/visitorAssignment.ts
index 802a95e3..0d9c9b6a 100644
--- a/src/lib/navAssignment.ts
+++ b/src/lib/visitorAssignment.ts
@@ -1,24 +1,20 @@
import { getEnv } from "../utils/getEnv";
-import {
- NAV_LABEL_EXPERIMENT,
- type NavLabelVariant,
- variantFromFeature,
-} from "../utils/navLabelExperiment";
-import { evalServerFeature, loadFeaturePayload } from "./growthbookServer";
// A/B test id that is stable for one visitor for one UTC day, without storing anything on
// the visitor's device. Same idea as Plausible's own visitor id: a keyed hash of the date,
// the IP and the User-Agent. The IP and User-Agent are only read here, in memory, and never
// stored; the hash never leaves the server (GrowthBook evaluates it in-process, see
-// src/lib/growthbookServer.ts).
+// src/lib/growthbookServer.ts). Used by the homepage hero photo test
+// (src/lib/heroPhotoAssignment.ts).
//
// The date is part of the hash input, so the id rotates daily with no stored salt.
//
-// The test is only meaningful if a visitor keeps one label, because the sign-up on /membership
-// is credited to the label on that page. So without the secret, or without an IP (pnpm dev),
-// there is no assignment at all: everyone sees "Get Involved" and nothing is tracked, rather
-// than a random label per page that would make the result noise.
+// A test is only meaningful if a visitor keeps one variant. So without the secret, or without
+// an IP (pnpm dev), there is no id at all: callers show their control and track nothing,
+// rather than a random variant per page that would make the result noise.
+// The name predates the hero photo test (it was first used by the navbar label test) and is
+// kept because it is what the Cloudflare Pages environment sets.
export const ASSIGNMENT_SECRET_ENV = "NAV_ASSIGNMENT_SECRET";
const IPV6_PREFIX_GROUPS = 4;
@@ -92,7 +88,7 @@ export async function requestAssignmentId(
if (!secret) {
if (ip && !warnedMissingSecret) {
warnedMissingSecret = true;
- console.warn(`${ASSIGNMENT_SECRET_ENV} is not set: the nav label A/B test is inactive`);
+ console.warn(`${ASSIGNMENT_SECRET_ENV} is not set: server-side A/B tests are inactive`);
}
return null;
}
@@ -104,18 +100,3 @@ export async function requestAssignmentId(
date: now(),
});
}
-
-/** The nav label variant GrowthBook assigns this visitor, or null when they are not in the
- * test (flag off, CDN down, or no stable id). `now` is for tests. */
-export async function assignNavLabelVariant(
- request: Request,
- locals: unknown,
- now?: () => Date
-): Promise {
- const clientKey = getEnv("PUBLIC_GROWTHBOOK_CLIENT_KEY", locals);
- const payload = clientKey ? await loadFeaturePayload(clientKey) : undefined;
- if (!payload) return null;
- const id = await requestAssignmentId(request, locals, now);
- if (!id) return null;
- return variantFromFeature(evalServerFeature(payload, NAV_LABEL_EXPERIMENT, id));
-}
diff --git a/src/middleware/cache-control.ts b/src/middleware/cache-control.ts
index 89f8e267..24ffa509 100644
--- a/src/middleware/cache-control.ts
+++ b/src/middleware/cache-control.ts
@@ -3,9 +3,10 @@ import { defineMiddleware } from "astro:middleware";
export const cacheControl = defineMiddleware(async (context, next) => {
const response = await next();
- // Pages are `private`: the navbar label is an A/B test picked per request
- // (src/components/Navigation.astro), so a shared cache must not store one
- // visitor's variant and serve it to everyone. Browsers may still cache for 10 minutes.
+ // Pages are `private`: the homepage hero photo A/B test (src/pages/index.astro,
+ // src/lib/heroPhotoAssignment.ts) picks a variant per visitor, so a shared cache must not
+ // store one visitor's variant and serve it to everyone. Browsers may still cache for
+ // 10 minutes.
const pathname = context.url.pathname;
const isApi = pathname.startsWith("/api/");
diff --git a/src/pages/donate-2.astro b/src/pages/donate-2.astro
index 59c43b6b..cde03d63 100644
--- a/src/pages/donate-2.astro
+++ b/src/pages/donate-2.astro
@@ -189,6 +189,7 @@ import "../styles/base.css";
if (typeof (window as any).plausible !== "undefined") {
(window as any).plausible("Donate Form", {
props: { donate_form_variant: "charitystack" },
+ interactive: false,
});
}
diff --git a/src/pages/donate.astro b/src/pages/donate.astro
index 8b4967b0..1934d984 100644
--- a/src/pages/donate.astro
+++ b/src/pages/donate.astro
@@ -1,5 +1,6 @@
---
import Layout from "../layouts/Layout.astro";
+import OtherWaysToGive from "../components/donate/OtherWaysToGive.astro";
import "../styles/base.css";
// Get country from Cloudflare headers
@@ -166,44 +167,7 @@ const isUK = country === "GB";
-
-
Other ways to give
-
-
-
Stock & Cryptocurrency
-
- To make a gift via stock or cryptocurrency, visit our form here.
-