@se-studio/ab-testing 1.0.82 → 1.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/docs/llms.md +106 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
package/docs/llms.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @se-studio/ab-testing — LLM Reference
|
|
2
|
+
|
|
3
|
+
Server-side A/B testing framework for Next.js App Router with Contentful CMS. Variants are assigned via cookies; decisions happen in Next.js middleware.
|
|
4
|
+
|
|
5
|
+
## Core Concepts
|
|
6
|
+
|
|
7
|
+
- **Test**: a named experiment with 2+ variants, each mapped to a URL path
|
|
8
|
+
- **Assignment**: a cookie that records which variant a user is seeing
|
|
9
|
+
- **Middleware**: intercepts requests and rewrites URLs to the assigned variant path
|
|
10
|
+
|
|
11
|
+
## Key Types
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import type {
|
|
15
|
+
AbTest, // { id, name, variants: AbTestVariant[] }
|
|
16
|
+
AbTestVariant, // { id, name, path: string, weight: number }
|
|
17
|
+
AbTestAssignment, // { testId, variantId }
|
|
18
|
+
AbTestCookie, // serialised cookie value
|
|
19
|
+
AbTestVariantConfig, // { variantId, contentPath }
|
|
20
|
+
IBlobStore, // storage interface for test configs (Vercel Blob)
|
|
21
|
+
} from '@se-studio/ab-testing';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Middleware Setup
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// middleware.ts
|
|
28
|
+
import { createAbTestMiddleware } from '@se-studio/ab-testing';
|
|
29
|
+
|
|
30
|
+
const abTestMiddleware = createAbTestMiddleware({
|
|
31
|
+
blobStore, // IBlobStore — fetches test configs from Vercel Blob
|
|
32
|
+
cookieName: 'ab_assignment', // optional, default: DEFAULT_COOKIE_NAME
|
|
33
|
+
cookieMaxAge: 60 * 60 * 24 * 30, // optional, default: DEFAULT_COOKIE_MAX_AGE
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export async function middleware(request: NextRequest) {
|
|
37
|
+
return abTestMiddleware(request);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For static (no blob store) tests:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createStaticAbTestMiddleware } from '@se-studio/ab-testing';
|
|
45
|
+
|
|
46
|
+
const abTestMiddleware = createStaticAbTestMiddleware({
|
|
47
|
+
tests: [
|
|
48
|
+
{
|
|
49
|
+
id: 'hero-test',
|
|
50
|
+
variants: [
|
|
51
|
+
{ id: 'control', path: '/home', weight: 50 },
|
|
52
|
+
{ id: 'variant-a', path: '/home-v2', weight: 50 },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Reading the Assignment (Client / Server)
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { useAbTestAssignments } from '@se-studio/ab-testing';
|
|
63
|
+
|
|
64
|
+
// In a React component:
|
|
65
|
+
const { assignments, isLoading } = useAbTestAssignments({ testIds: ['hero-test'] });
|
|
66
|
+
const variant = assignments['hero-test']; // AbTestAssignment | undefined
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Webhook Handler (Contentful → update test cache)
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { createWebhookHandler } from '@se-studio/ab-testing';
|
|
73
|
+
|
|
74
|
+
const handler = createWebhookHandler({
|
|
75
|
+
blobStore,
|
|
76
|
+
secret: process.env.WEBHOOK_SECRET!,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// In a Next.js route handler:
|
|
80
|
+
export const POST = handler.handle;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Cookie Utilities
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import {
|
|
87
|
+
parseCookie,
|
|
88
|
+
serializeCookie,
|
|
89
|
+
readCookieFromDocument, // client-side
|
|
90
|
+
DEFAULT_COOKIE_NAME,
|
|
91
|
+
DEFAULT_COOKIE_MAX_AGE,
|
|
92
|
+
} from '@se-studio/ab-testing';
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Low-Level Utilities
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import {
|
|
99
|
+
selectVariant, // weighted random variant selection
|
|
100
|
+
getAssignment, // read assignment from cookies
|
|
101
|
+
setAssignment, // write assignment to response cookies
|
|
102
|
+
isValidAssignment, // validate an assignment object
|
|
103
|
+
normalizePath, // normalise URL paths for comparison
|
|
104
|
+
findCanonicalPath, // resolve variant path back to canonical
|
|
105
|
+
} from '@se-studio/ab-testing';
|
|
106
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@se-studio/ab-testing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.84",
|
|
4
4
|
"description": "Server-side A/B testing framework for Next.js applications with Contentful CMS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"dist",
|
|
45
|
-
"*.md"
|
|
45
|
+
"*.md",
|
|
46
|
+
"docs"
|
|
46
47
|
],
|
|
47
48
|
"keywords": [
|
|
48
49
|
"ab-testing",
|