Skip to content

Commit 594e87c

Browse files
authored
Merge pull request #15167 from guardian/dina/admin-ab-tests-CODE-route
Fix AB tests admin opt-in/opt-out `CODE` routes
2 parents f0f3907 + 41ef9aa commit 594e87c

7 files changed

Lines changed: 36 additions & 10 deletions

File tree

.github/workflows/ab-testing-ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ jobs:
6363
- name: Set up Node environment
6464
uses: ./.github/actions/setup-node-env
6565

66-
- name: Build UI
67-
run: pnpm build
66+
- name: Build UI for CODE
67+
if: github.ref != 'refs/heads/main'
68+
run: AB_TESTING_ENV=code pnpm build
69+
70+
- name: Build UI for PROD
71+
if: github.ref == 'refs/heads/main'
72+
run: AB_TESTING_ENV=production pnpm build
6873

6974
- name: Save build
7075
uses: actions/upload-artifact@v5

ab-testing/config/abTests.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import type { ABTest } from "./types.ts";
22

3+
/**
4+
* URL for AB test opt-in/opt-out links
5+
* PROD: https://www.theguardian.com/
6+
* CODE: https://m.code.dev-theguardian.com/
7+
*/
8+
const hostname =
9+
process.env.AB_TESTING_ENV === "code"
10+
? "https://m.code.dev-theguardian.com"
11+
: "https://www.theguardian.com";
12+
313
/**
414
* Tests are defined here. They will be assigned mvt ranges based on the
515
* size of the test and the number of groups, these ranges may not be contiguous.
@@ -74,4 +84,4 @@ const ABTests: ABTest[] = [
7484

7585
const activeABtests = ABTests.filter((test) => test.status === "ON");
7686

77-
export { ABTests as allABTests, activeABtests };
87+
export { ABTests as allABTests, activeABtests, hostname };

ab-testing/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// this file is covered by the dotcom-rendering tsconfig.json,
22
// not the one in this directory (hence no need for .ts extension)
3-
export { activeABtests, allABTests } from "./abTests";
3+
export { activeABtests, allABTests, hostname } from "./abTests";
44
export type { ABTest } from "./types";

ab-testing/frontend/src/lib/components/TestVariants.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import { hostname } from "@guardian/ab-testing-config";
3+
24
interface Props {
35
testName: string;
46
testGroups: string[];
@@ -26,15 +28,15 @@
2628
</td>
2729
<td>
2830
<a
29-
href={`https://www.theguardian.com/ab-tests/opt-in/${testName}:${group}`}
31+
href={`${hostname}/ab-tests/opt-in/${testName}:${group}`}
3032
target="_blank"
3133
>
3234
opt in
3335
</a>
3436
</td>
3537
<td>
3638
<a
37-
href={`https://www.theguardian.com/ab-tests/opt-out/${testName}:${group}`}
39+
href={`${hostname}/ab-tests/opt-out/${testName}:${group}`}
3840
target="_blank"
3941
>
4042
opt out

ab-testing/frontend/src/routes/+page.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<script lang="ts">
2-
import { allABTests, activeABtests } from "@guardian/ab-testing-config";
2+
import {
3+
allABTests,
4+
activeABtests,
5+
hostname,
6+
} from "@guardian/ab-testing-config";
37
import Table from "$lib/components/TableFixed.svelte";
48
import AudienceBreakdown from "$lib/components/AudienceBreakdown.svelte";
59
</script>
@@ -15,7 +19,7 @@
1519
</p>
1620
<p>
1721
AB tests are defined in <a
18-
href="https://github.com/guardian/dotcom-rendering/blob/main/ab-testing/abTest.ts"
22+
href="https://github.com/guardian/dotcom-rendering/blob/main/ab-testing/config/abTests.ts"
1923
>guardian/dotcom-rendering</a
2024
>
2125
</p>
@@ -24,7 +28,7 @@
2428
this will override any cookie based test assignment.
2529
</p>
2630
<p>
27-
<a href="https://www.theguardian.com/ab-tests/opt-out"
31+
<a href={`${hostname}/ab-tests/opt-out`}
2832
>Use this link to opt out of all tests you've opted into</a
2933
>
3034
</p>

ab-testing/frontend/vite.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ import { defineConfig } from "vite";
33

44
export default defineConfig({
55
plugins: [sveltekit()],
6+
define: {
7+
"process.env.AB_TESTING_ENV": JSON.stringify(
8+
process.env.AB_TESTING_ENV || "production",
9+
),
10+
},
611
});

dotcom-rendering/docs/development/ab-testing-in-dcr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ If you want to test your changes on CODE you need to follow these steps:
139139

140140
2. Deploy your code changes on DCR and/or Frontend to CODE as normal
141141

142-
3. Deploy the A/B test config to CODE by deploying the `dotcom::ab-testing` riff-raff project against your branch, there will be a comment in the PR with a link to do this once the config has been validated.
142+
3. Deploy the A/B test config to CODE by deploying the `dotcom:ab-testing` riff-raff project against your branch, there will be a comment in the PR with a link to do this once the config has been validated.
143143

144144
The 3rd step is crucial as Fastly buckets users into tests/cohorts and returns your A/B test participations as response headers.
145145

0 commit comments

Comments
 (0)