@sanity/personalization-plugin
3.1.83.1.9
README.md~
README.mdModified+7−6
Index: package/README.md
===================================================================
--- package/README.md
+++ package/README.md
@@ -84,10 +84,10 @@
Add it as a plugin in `sanity.config.ts` (or .js):
```ts
-import {defineConfig} from 'sanity'
import {fieldLevelExperiments} from '@sanity/personalization-plugin'
+import {defineConfig} from 'sanity'
// Example: Testing different homepage headlines
const headlineExperiment = {
id: 'homepage-headline',
@@ -241,10 +241,10 @@
For more control over the value field, you can pass a schema definition into the fields array.
```ts
-import {defineConfig, defineField} from 'sanity'
import {fieldLevelExperiments} from '@sanity/personalization-plugin'
+import {defineConfig, defineField} from 'sanity'
export default defineConfig({
//...
plugins: [
@@ -281,10 +281,10 @@
### Step 1: Configure the Plugin with a Reference Field
```ts
-import {defineConfig, defineField} from 'sanity'
import {fieldLevelExperiments} from '@sanity/personalization-plugin'
+import {defineConfig, defineField} from 'sanity'
const homepageExperiment = {
id: 'homepage-redesign',
label: 'Homepage Redesign Test',
@@ -534,13 +534,13 @@
The most common approach is to assign variants via cookies on first visit. Using MurmurHash with a userId gives better distribution and deterministic assignment (the same user always gets the same variant):
```ts
+import MurmurHash3 from 'imurmurhash'
// In Next.js proxy (proxy.ts)
import {NextResponse} from 'next/server'
import type {NextRequest} from 'next/server'
import {v4} from 'uuid'
-import MurmurHash3 from 'imurmurhash'
const COOKIE_MAX_AGE = 60 * 60 * 24 * 30 // 30 days
export function proxy(request: NextRequest) {
@@ -681,13 +681,14 @@
Use a proxy to intercept requests and route users to the appropriate page based on their variant assignment:
```ts
+import MurmurHash3 from 'imurmurhash'
// proxy.ts
import {NextResponse} from 'next/server'
import type {NextRequest} from 'next/server'
import {v4} from 'uuid'
-import MurmurHash3 from 'imurmurhash'
+
import {client} from './lib/sanity'
const ROUTING_QUERY = `*[
_type == "routing" &&
@@ -793,10 +794,10 @@
### Example: Audience Segmentation
```ts
-import {defineConfig} from 'sanity'
import {fieldLevelExperiments} from '@sanity/personalization-plugin'
+import {defineConfig} from 'sanity'
// Define your audiences and segments
const audiences = [
{