@@ -4,6 +4,8 @@ type MatomoExperiment = {
4
4
idexperiment : string
5
5
name : string
6
6
status : string
7
+ start_date ?: string
8
+ end_date ?: string
7
9
variations : Array < {
8
10
name : string
9
11
percentage : number
@@ -19,6 +21,30 @@ type ABTestConfig = {
19
21
} >
20
22
}
21
23
24
+ function isExperimentActive ( experiment : MatomoExperiment ) : boolean {
25
+ const now = new Date ( )
26
+
27
+ // Check start date - if scheduled for future, not active yet
28
+ if ( experiment . start_date ) {
29
+ const startDate = new Date ( experiment . start_date )
30
+ if ( now < startDate ) {
31
+ return false // Not started yet
32
+ }
33
+ }
34
+
35
+ // Check end date - if past end date, not active anymore
36
+ if ( experiment . end_date ) {
37
+ const endDate = new Date ( experiment . end_date )
38
+ if ( now > endDate ) {
39
+ return false // Already ended
40
+ }
41
+ }
42
+
43
+ // If no scheduling constraints, enabled if created or running
44
+ // If within time window, enabled if running
45
+ return [ "created" , "running" ] . includes ( experiment . status )
46
+ }
47
+
22
48
export async function GET ( ) {
23
49
try {
24
50
const matomoUrl = process . env . NEXT_PUBLIC_MATOMO_URL
@@ -91,12 +117,8 @@ export async function GET() {
91
117
const config : Record < string , ABTestConfig > = { }
92
118
93
119
experiments . forEach ( ( exp ) => {
94
- // Include running experiments (Matomo uses "running" not "active")
95
- if (
96
- exp . status === "running" &&
97
- exp . variations &&
98
- exp . variations . length > 0
99
- ) {
120
+ // Include all experiments with variations (let scheduling handle timing)
121
+ if ( exp . variations && exp . variations . length > 0 ) {
100
122
// Calculate Original variant weight (100% - sum of all variations)
101
123
const variationsTotalWeight = exp . variations . reduce (
102
124
( sum , variation ) => {
@@ -119,7 +141,7 @@ export async function GET() {
119
141
120
142
config [ exp . name ] = {
121
143
id : exp . idexperiment ,
122
- enabled : true ,
144
+ enabled : isExperimentActive ( exp ) ,
123
145
variants : variants ,
124
146
}
125
147
}
0 commit comments