Skip to content

Commit e59e79b

Browse files
author
Marcin Komorski
committed
update with new functionalities
1 parent 4a0be38 commit e59e79b

File tree

1 file changed

+107
-3
lines changed

1 file changed

+107
-3
lines changed

dev-docs/modules/shapingRulesModule.md

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The Prebid.js Shaping Rules module processes JSON data in the floors-syntax form
3434
### Example
3535

3636
This example shows the scenario when `bidderA` and `bidderD` are excluded from auction
37-
in Japan
37+
in Japan. It can be provided either statically or by fetching it from external endpoint
3838

3939
```javascript
4040
{
@@ -127,6 +127,7 @@ in Japan
127127
| `domain` | null | Return publisher.domain or domain from {site, app, dooh}. |
128128
| `domainIn` | array of strings | true if any supplied domain matches publisher.domain or domain. |
129129
| `bundleIn` | array of strings | true if any supplied value matches app.bundle. |
130+
| `bundle` | null | return app.bundle |
130131
| `mediaTypeIn` | array of strings | true if any supplied mediaType is present in imp. |
131132
| `adUnitCode` | null | Return first of: imp.ext.gpid, imp.tagid, imp.ext.data.pbadslot, imp.ext.prebid.storedrequest.id. |
132133
| `adUnitCodeIn` | array of strings | true if any supplied string matches imp.ext.gpid, imp.tagid, imp.ext.data.pbadslot, imp.ext.prebid.storedrequest.id, imp.id. |
@@ -154,11 +155,13 @@ The function argument is an array of objects, each of which may include the foll
154155

155156
## Module configuration
156157

157-
### Example config
158+
### Configuration
159+
160+
You can provide an external endpoint that returns a JSON object containing the rules. In this case, you should also specify the `auctionDelay` parameter, which delays the auction to allow time for the rules to be fetched.
158161

159162
```javascript
160163
pbjs.setConfig({
161-
rules: {
164+
shapingRules: {
162165
auctionDelay: 2000, // maximum time (in ms) the auction may wait for the rules endpoint to respond
163166
endpoint: {
164167
url: 'http://rules-config-endpoint.com/shaping-rules',
@@ -167,3 +170,104 @@ The function argument is an array of objects, each of which may include the foll
167170
}
168171
})
169172
```
173+
174+
Alternatively, you can define the rules statically by providing the configuration inline using the `rules` field:
175+
176+
```javascript
177+
pbjs.setConfig({
178+
shapingRules: {
179+
rules: {
180+
enabled: true,
181+
rulesets: [
182+
{
183+
stage: "processed-auction-request",
184+
name: "exclude-in-jpn",
185+
version: "1234",
186+
modelGroups: [
187+
{
188+
weight: 98,
189+
analyticsKey: "experiment-name",
190+
version: "4567",
191+
schema: [
192+
{
193+
function: "deviceCountryIn",
194+
args: [["JPN"]],
195+
},
196+
],
197+
rules: [
198+
{
199+
conditions: ["true"],
200+
results: [
201+
{
202+
function: "excludeBidders",
203+
args: [
204+
{
205+
bidders: ["testBidder"],
206+
analyticsValue: "rmjpn",
207+
},
208+
],
209+
},
210+
],
211+
},
212+
],
213+
},
214+
],
215+
},
216+
],
217+
},
218+
},
219+
});
220+
```
221+
222+
The configuration also allows you to define custom schema evaluators using the `extraSchemaEvaluators` field.
223+
224+
```javascript
225+
pbjs.setConfig({
226+
shapingRules: {
227+
extraSchemaEvaluators: {
228+
browser: (args, context) => {
229+
if (navigator.userAgent.includes("Chrome")) {
230+
return "Chrome";
231+
}
232+
},
233+
},
234+
rules: {
235+
enabled: true,
236+
rulesets: [
237+
{
238+
stage: "processed-auction-request",
239+
name: "exclude-in-jpn",
240+
version: "1234",
241+
modelGroups: [
242+
{
243+
weight: 98,
244+
analyticsKey: "experiment-name",
245+
version: "4567",
246+
schema: [
247+
{
248+
function: "browser",
249+
},
250+
],
251+
rules: [
252+
{
253+
conditions: ["Chrome"],
254+
results: [
255+
{
256+
function: "excludeBidders",
257+
args: [
258+
{
259+
bidders: ["testBidder"],
260+
},
261+
],
262+
},
263+
],
264+
},
265+
],
266+
},
267+
],
268+
},
269+
],
270+
},
271+
},
272+
});
273+
```

0 commit comments

Comments
 (0)