@sanity/personalization-plugin 2.1.0-growthbook.1 → 2.2.0-launch-darkly.1
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/README.md +60 -6
- package/dist/index.d.mts +190 -191
- package/dist/index.d.ts +190 -191
- package/dist/index.js +188 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/Array.tsx +11 -12
- package/src/components/ExperimentContext.tsx +6 -1
- package/src/components/ExperimentField.tsx +71 -39
- package/src/components/ExperimentInput.tsx +5 -2
- package/src/components/Secrets.tsx +2 -4
- package/src/components/VariantInput.tsx +15 -68
- package/src/fieldExperiments.tsx +99 -34
- package/src/index.ts +1 -1
- package/src/{growthbookFieldExperiments.tsx → launchDarklyExperiments.tsx} +8 -11
- package/src/types.ts +186 -173
- package/src/utils/launchDarkly.ts +54 -0
- package/src/utils/growthbook.ts +0 -78
package/README.md
CHANGED
|
@@ -25,8 +25,6 @@ Once configured you can query the values using the ids of the experiment and var
|
|
|
25
25
|
- [Release new version](#release-new-version)
|
|
26
26
|
- [License](#license-1)
|
|
27
27
|
|
|
28
|
-
For Specific information about the growthbookFieldLevel export see its [readme](/growthbook.md)
|
|
29
|
-
|
|
30
28
|
## Installation
|
|
31
29
|
|
|
32
30
|
```sh
|
|
@@ -85,8 +83,8 @@ export default defineConfig({
|
|
|
85
83
|
|
|
86
84
|
This will register two new fields to the schema., based on the setting passed intto `fields:`
|
|
87
85
|
|
|
88
|
-
- `experimentString` an Object field with `string` field called `default`, a `string` field called `experimentId` and an array field of type:
|
|
89
|
-
- `
|
|
86
|
+
- `experimentString` an Object field with `string` field called `default`, a `string` field called `experimentId` and an array field called `variants` of type:
|
|
87
|
+
- `variantString` an object field with a `string` field called `value`, a string field called `variantId`, a `string` field called `experimentId`.
|
|
90
88
|
|
|
91
89
|
Use the experiment field in your schema like this:
|
|
92
90
|
|
|
@@ -202,7 +200,7 @@ export default defineConfig({
|
|
|
202
200
|
|
|
203
201
|
This would also create two new fields in your schema.
|
|
204
202
|
|
|
205
|
-
- `experimentFeaturedProduct` an Object field with `reference` field called `default`, a `string` field called `experimentId` and an array field of type:
|
|
203
|
+
- `experimentFeaturedProduct` an Object field with `reference` field called `default`, a `string` field called `experimentId` and an array field called `variants` of type:
|
|
206
204
|
- `variantFeaturedProduct` an object field with a `reference` field called `value`, a string field called `variandId`, a `string` field called `experimentId`.
|
|
207
205
|
|
|
208
206
|
Note that the name key in the field gets rewritten to value and is instead used to name the object field.
|
|
@@ -242,7 +240,7 @@ The custom input contains buttons which will add new array items with the experi
|
|
|
242
240
|
```json
|
|
243
241
|
"title": {
|
|
244
242
|
"default": "asdf",
|
|
245
|
-
"
|
|
243
|
+
"experimentId": "test-1",
|
|
246
244
|
"variants": [
|
|
247
245
|
{
|
|
248
246
|
"experimentId": "test-1",
|
|
@@ -267,6 +265,62 @@ Using GROQ filters you can query for a specific experitment, with a fallback to
|
|
|
267
265
|
}
|
|
268
266
|
```
|
|
269
267
|
|
|
268
|
+
## Overwriting the experiment and variant field names
|
|
269
|
+
|
|
270
|
+
If your use case does not match exactly with experiments you can overwrite the name field names for experiment and variant in the config.
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
import {defineConfig} from 'sanity'
|
|
274
|
+
import {fieldLevelExperiments} from '@sanity/personalization-plugin'
|
|
275
|
+
|
|
276
|
+
export default defineConfig({
|
|
277
|
+
//...
|
|
278
|
+
plugins: [
|
|
279
|
+
//...
|
|
280
|
+
fieldLevelExperiments({
|
|
281
|
+
fields: ['string'],
|
|
282
|
+
experiments: [experiment1, experiment2],
|
|
283
|
+
experimentNameOverride: 'audience',
|
|
284
|
+
variantNameOverride: 'segment',
|
|
285
|
+
}),
|
|
286
|
+
],
|
|
287
|
+
})
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
This would also create two new fields in your schema.
|
|
291
|
+
|
|
292
|
+
- `audienceString` an Object field with `string` field called `default`, a `string` field called `audienceId` and an array field called `segments` of type:
|
|
293
|
+
- `segmentString` an object field with a `string` field called `value`, a string field called `segmentId`, a `string` field called `audienceId`.
|
|
294
|
+
|
|
295
|
+
the data will be stored as
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
"title": {
|
|
299
|
+
"default": "asdf",
|
|
300
|
+
"audienceId": "test-1",
|
|
301
|
+
"segments": [
|
|
302
|
+
{
|
|
303
|
+
"audienceId": "test-1",
|
|
304
|
+
"value": "asdf",
|
|
305
|
+
"segmentId": "test-1-a"
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
"audienceId": "test-1",
|
|
309
|
+
"segmentId": "test-1-b",
|
|
310
|
+
"value": "qwer"
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
This will also affect the query you write to fetch data to be:
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
*[_type == "post"] {
|
|
320
|
+
"title":coalesce(title.segments[audienceId == $audience && segmentId == $segment][0].value, title.default),
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
270
324
|
## License
|
|
271
325
|
|
|
272
326
|
[MIT](LICENSE) © Jon Burbridge
|
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,9 @@ import {SchemaType} from 'sanity'
|
|
|
10
10
|
import {SetStateAction} from 'react'
|
|
11
11
|
|
|
12
12
|
export declare type ArrayInputProps = ArrayOfObjectsInputProps & {
|
|
13
|
-
|
|
13
|
+
variantName: string
|
|
14
|
+
variantId: string
|
|
15
|
+
experimentId: string
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export declare type ExperimentContextProps = Required<FieldPluginConfig> & {
|
|
@@ -23,11 +25,15 @@ export declare type ExperimentGeneric<T> = {
|
|
|
23
25
|
_type: string
|
|
24
26
|
default?: T
|
|
25
27
|
experimentValue?: string
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
[key: string]:
|
|
29
|
+
| Array<
|
|
30
|
+
{
|
|
31
|
+
_key: string
|
|
32
|
+
} & VariantGeneric<T>
|
|
33
|
+
>
|
|
34
|
+
| string
|
|
35
|
+
| T
|
|
36
|
+
| undefined
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export declare type ExperimentType = {
|
|
@@ -40,10 +46,13 @@ export declare const fieldLevelExperiments: Plugin_2<FieldPluginConfig>
|
|
|
40
46
|
|
|
41
47
|
export declare type FieldPluginConfig = {
|
|
42
48
|
fields: (string | FieldDefinition)[]
|
|
43
|
-
experiments:
|
|
44
|
-
| ExperimentType[]
|
|
45
|
-
| ((client: SanityClient, secret?: string) => Promise<ExperimentType[]>)
|
|
49
|
+
experiments: ExperimentType[] | ((client: SanityClient) => Promise<ExperimentType[]>)
|
|
46
50
|
apiVersion?: string
|
|
51
|
+
experimentNameOverride?: string
|
|
52
|
+
variantNameOverride?: string
|
|
53
|
+
variantId?: string
|
|
54
|
+
variantArrayName?: string
|
|
55
|
+
experimentId?: string
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
/**
|
|
@@ -51,218 +60,208 @@ export declare type FieldPluginConfig = {
|
|
|
51
60
|
*/
|
|
52
61
|
export declare function flattenSchemaType(schemaType: SchemaType): ObjectFieldWithPath[]
|
|
53
62
|
|
|
54
|
-
export declare
|
|
63
|
+
export declare const launchDarklyFieldLevel: Plugin_2<LaunchDarklyFieldLevelConfig>
|
|
64
|
+
|
|
65
|
+
export declare type LaunchDarklyFieldLevelConfig = {
|
|
55
66
|
fields: (string | FieldDefinition)[]
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
project?: string
|
|
59
|
-
convertBooleans?: boolean
|
|
67
|
+
projectKey: string
|
|
68
|
+
tags?: string[]
|
|
60
69
|
}
|
|
61
70
|
|
|
62
|
-
export declare type
|
|
63
|
-
id: string
|
|
64
|
-
dateCreated: string
|
|
65
|
-
dateUpdated: string
|
|
71
|
+
export declare type LaunchDarklyFlagItem = {
|
|
66
72
|
name: string
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
targetingCondition: string
|
|
109
|
-
savedGroupTargeting: [
|
|
110
|
-
{
|
|
111
|
-
matchType: string
|
|
112
|
-
savedGroups: [string]
|
|
113
|
-
},
|
|
114
|
-
]
|
|
115
|
-
},
|
|
116
|
-
]
|
|
117
|
-
settings: {
|
|
118
|
-
datasourceId: string
|
|
119
|
-
assignmentQueryId: string
|
|
120
|
-
experimentId: string
|
|
121
|
-
segmentId: string
|
|
122
|
-
queryFilter: string
|
|
123
|
-
inProgressConversions: string
|
|
124
|
-
attributionModel: string
|
|
125
|
-
statsEngine: string
|
|
126
|
-
regressionAdjustmentEnabled: boolean
|
|
127
|
-
goals: [
|
|
128
|
-
{
|
|
129
|
-
metricId: string
|
|
130
|
-
overrides: {
|
|
131
|
-
delayHours: 0
|
|
132
|
-
windowHours: 0
|
|
133
|
-
window: string
|
|
134
|
-
winRiskThreshold: 0
|
|
135
|
-
loseRiskThreshold: 0
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
]
|
|
139
|
-
secondaryMetrics: [
|
|
140
|
-
{
|
|
141
|
-
metricId: string
|
|
142
|
-
overrides: {
|
|
143
|
-
delayHours: 0
|
|
144
|
-
windowHours: 0
|
|
145
|
-
window: string
|
|
146
|
-
winRiskThreshold: 0
|
|
147
|
-
loseRiskThreshold: 0
|
|
73
|
+
kind: string
|
|
74
|
+
key: string
|
|
75
|
+
_version: number
|
|
76
|
+
creationDate: number
|
|
77
|
+
variations: Array<{
|
|
78
|
+
value: boolean
|
|
79
|
+
_id: string
|
|
80
|
+
name: string
|
|
81
|
+
}>
|
|
82
|
+
temporary: boolean
|
|
83
|
+
tags: string[]
|
|
84
|
+
_links: {
|
|
85
|
+
parent: {
|
|
86
|
+
href: string
|
|
87
|
+
type: string
|
|
88
|
+
}
|
|
89
|
+
self: {
|
|
90
|
+
href: string
|
|
91
|
+
type: string
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
experiments: {
|
|
95
|
+
baselineIdx: number
|
|
96
|
+
items: Array<{
|
|
97
|
+
metricKey: string
|
|
98
|
+
_metric: {
|
|
99
|
+
_id: string
|
|
100
|
+
_versionId: string
|
|
101
|
+
key: string
|
|
102
|
+
name: string
|
|
103
|
+
kind: string
|
|
104
|
+
_links: {
|
|
105
|
+
parent: {
|
|
106
|
+
href: string
|
|
107
|
+
type: string
|
|
108
|
+
}
|
|
109
|
+
self: {
|
|
110
|
+
href: string
|
|
111
|
+
type: string
|
|
112
|
+
}
|
|
148
113
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
114
|
+
tags: string[]
|
|
115
|
+
_creationDate: number
|
|
116
|
+
experimentCount: number
|
|
117
|
+
metricGroupCount: number
|
|
118
|
+
_attachedFlagCount: number
|
|
119
|
+
maintainerId: string
|
|
120
|
+
_maintainer: {
|
|
121
|
+
_links: {
|
|
122
|
+
self: {
|
|
123
|
+
href: string
|
|
124
|
+
type: string
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
_id: string
|
|
128
|
+
role: string
|
|
129
|
+
email: string
|
|
130
|
+
firstName: string
|
|
131
|
+
lastName: string
|
|
160
132
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
metricId: string
|
|
165
|
-
overrides: {
|
|
166
|
-
delayHours: 0
|
|
167
|
-
windowHours: 0
|
|
168
|
-
window: string
|
|
169
|
-
winRiskThreshold: 0
|
|
170
|
-
loseRiskThreshold: 0
|
|
133
|
+
category: string
|
|
134
|
+
isNumeric: boolean
|
|
135
|
+
percentileValue: number
|
|
171
136
|
}
|
|
172
|
-
}
|
|
137
|
+
}>
|
|
173
138
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
excludeFromPayload: boolean
|
|
139
|
+
customProperties: {
|
|
140
|
+
key: {
|
|
141
|
+
name: string
|
|
142
|
+
value: string[]
|
|
143
|
+
}
|
|
180
144
|
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export declare type GrowthbookFeature = {
|
|
184
|
-
id: string
|
|
185
|
-
dateCreated: string
|
|
186
|
-
dateUpdated: string
|
|
187
145
|
archived: boolean
|
|
188
146
|
description: string
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
147
|
+
maintainerId: string
|
|
148
|
+
_maintainer: {
|
|
149
|
+
_links: {
|
|
150
|
+
self: {
|
|
151
|
+
href: string
|
|
152
|
+
type: string
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
_id: string
|
|
156
|
+
role: string
|
|
157
|
+
email: string
|
|
158
|
+
firstName: string
|
|
159
|
+
lastName: string
|
|
160
|
+
}
|
|
161
|
+
maintainerTeamKey: string
|
|
162
|
+
_maintainerTeam: {
|
|
163
|
+
key: string
|
|
164
|
+
name: string
|
|
165
|
+
_links: {
|
|
166
|
+
parent: {
|
|
167
|
+
href: string
|
|
168
|
+
type: string
|
|
169
|
+
}
|
|
170
|
+
roles: {
|
|
171
|
+
href: string
|
|
172
|
+
type: string
|
|
173
|
+
}
|
|
174
|
+
self: {
|
|
175
|
+
href: string
|
|
176
|
+
type: string
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
archivedDate: number
|
|
181
|
+
deprecated: boolean
|
|
182
|
+
deprecatedDate: number
|
|
183
|
+
defaults: {
|
|
184
|
+
onVariation: number
|
|
185
|
+
offVariation: number
|
|
186
|
+
}
|
|
187
|
+
_purpose: string
|
|
188
|
+
migrationSettings: {
|
|
189
|
+
contextKind: string
|
|
190
|
+
stageCount: number
|
|
191
|
+
}
|
|
194
192
|
environments: {
|
|
195
193
|
[key: string]: {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}[]
|
|
205
|
-
id: string
|
|
206
|
-
enabled: boolean
|
|
194
|
+
on: boolean
|
|
195
|
+
archived: boolean
|
|
196
|
+
salt: string
|
|
197
|
+
sel: string
|
|
198
|
+
lastModified: number
|
|
199
|
+
version: number
|
|
200
|
+
_site: {
|
|
201
|
+
href: string
|
|
207
202
|
type: string
|
|
208
|
-
|
|
203
|
+
}
|
|
204
|
+
_environmentName: string
|
|
205
|
+
trackEvents: boolean
|
|
206
|
+
trackEventsFallthrough: boolean
|
|
207
|
+
targets: Array<{
|
|
208
|
+
values: string[]
|
|
209
|
+
variation: number
|
|
210
|
+
contextKind: string
|
|
211
|
+
}>
|
|
212
|
+
contextTargets: Array<{
|
|
213
|
+
values: string[]
|
|
214
|
+
variation: number
|
|
215
|
+
contextKind: string
|
|
216
|
+
}>
|
|
217
|
+
rules: Array<{
|
|
218
|
+
clauses: Array<{
|
|
219
|
+
attribute: string
|
|
220
|
+
op: string
|
|
221
|
+
values: unknown[]
|
|
222
|
+
negate: boolean
|
|
223
|
+
}>
|
|
224
|
+
trackEvents: boolean
|
|
225
|
+
}>
|
|
226
|
+
fallthrough: {
|
|
227
|
+
variation: number
|
|
228
|
+
}
|
|
229
|
+
offVariation: number
|
|
230
|
+
prerequisites: Array<{
|
|
231
|
+
key: string
|
|
232
|
+
variation: number
|
|
233
|
+
}>
|
|
234
|
+
_summary: {
|
|
209
235
|
variations: {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
condition: string
|
|
221
|
-
savedGroupTargeting: {
|
|
222
|
-
matchType: string
|
|
223
|
-
savedGroups: string[]
|
|
224
|
-
}[]
|
|
225
|
-
id: string
|
|
226
|
-
enabled: boolean
|
|
227
|
-
type: string
|
|
228
|
-
value: string
|
|
229
|
-
variations: {
|
|
230
|
-
value: string
|
|
231
|
-
variationId: string
|
|
232
|
-
}[]
|
|
233
|
-
}[]
|
|
234
|
-
definition: string
|
|
236
|
+
[key: string]: {
|
|
237
|
+
rules: number
|
|
238
|
+
nullRules: number
|
|
239
|
+
targets: number
|
|
240
|
+
contextTargets: number
|
|
241
|
+
isFallthrough?: boolean
|
|
242
|
+
isOff?: boolean
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
prerequisites: number
|
|
235
246
|
}
|
|
236
247
|
}
|
|
237
248
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
parentCondition: string
|
|
241
|
-
}[]
|
|
242
|
-
revision: {
|
|
243
|
-
version: number
|
|
244
|
-
comment: string
|
|
245
|
-
date: string
|
|
246
|
-
publishedBy: string
|
|
247
|
-
}
|
|
249
|
+
includeInSnippet: boolean
|
|
250
|
+
goalIds: string[]
|
|
248
251
|
}
|
|
249
252
|
|
|
250
|
-
export declare const growthbookFieldLevel: Plugin_2<GrowthbookABConfig>
|
|
251
|
-
|
|
252
253
|
export declare type ObjectFieldWithPath = ObjectField<SchemaType> & {
|
|
253
254
|
path: Path
|
|
254
255
|
}
|
|
255
256
|
|
|
256
257
|
export declare type VariantGeneric<T> = {
|
|
258
|
+
[key: string]: string | T | undefined
|
|
257
259
|
_type: string
|
|
258
|
-
variantId?: string
|
|
259
|
-
experimentId?: string
|
|
260
260
|
value?: T
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
export declare type VariantPreviewProps = Omit<PreviewProps, 'SchemaType'> & {
|
|
264
|
-
|
|
265
|
-
variant: string
|
|
264
|
+
[key: string]: string
|
|
266
265
|
value: any
|
|
267
266
|
}
|
|
268
267
|
|