Creating a rule
A Britva rule is a small JavaScript function that receives a single ad as input and decides what to do with it: pause it or, on the contrary, enable it. This article is a step-by-step guide on how to create a new rule in the editor.
Every rule is a checkAd(ad) function. Inside it you check the ad's metrics (through the ad.* fields) and, when the condition is met, call an action — for example, a pause. Read more about the principle itself — in the How automated rules work section.

How to create a rule
-
Open the Britva section and, on the Rules tab, click + New rule.

A separate page for the new rule editor will open (not a pop-up window).
-
Enter the rule Name in the field at the top (until you type, it shows the hint Short rule name) — short and clear, for example "Pause without deps".
-
Choose the rule scope in the dropdown next to the name: Global, Team or Personal. The dropdown appears only when you may choose between several options, and the options depend on your role (see Field reference). When an administrator picks Team, one more dropdown appears next to it with the list of teams. Its first item is empty and reads — select a team —; until you choose a team the rule does not save.
-
Write the rule code in the editor in the center. By default it already contains a template with the
checkAd(ad)function and a commented-out example:JavaScript/** @param {Ad} ad */function checkAd(ad) {// Example: pause when there are no deposits and the spend is high.// if (ad.deps_total === 0 && ad.spend_24h > 100) {// pauseAd('24h', 'no deps');// }}Uncomment the example or write your own logic. To recall which metrics are available, open the Macros tab on the right — it holds the full reference of
ad.*fields. Clicking any field inserts it into the code.
-
(Optional) Don't want to write code by hand — describe the task in words to the AI Assistant in the assistant panel of the window — by default it opens beside the window, on the left ("Pause ads with no deposits and spend above 100 per day"). The assistant will suggest ready code that you can insert into the editor in one click; the insert button is absent when you may not edit the rule's code.
-
Test the rule on the Test tab on the right — it will run on the current live ads and show which of them would be affected. This is safe: nothing is paused during the test. Read more — in the Testing a rule section.
-
Make sure the Enabled toggle is on, and click Create.
After saving, the rule appears in the list on the Rules tab and starts working in the common check cycle.
Create the rule disabled (turn the Enabled toggle off — its caption then changes to Disabled), run it on the Test tab, and only enable it once you are sure of the result. This way it does not trigger on live ads while you are still configuring it.
Field reference
The fields are gathered in a compact editor header, from left to right.
Name — a short name of the rule, by which you will find it in the list and in the logs. Required to save.
Scope — who sees the rule and which ads it checks (hover hint: Scope: who sees it and which ads it applies to). In the rules list the same three values are written as global, team: with the team number and user: with the user number:
- Personal — your personal rules, they check only your ads;
- Team — team rules: they check only the ads of the team. An administrator picks the team from the list that appears next to the scope (hover hint: The team whose ads this rule will apply to); anyone else gets their own team;
- Global — common rules for everyone (available only to administrators).
The list of options depends on your role. Personal is available to everyone; an administrator can choose all three. Team is also offered to a person who belongs to a team and whose permission template lets them edit Britva data for the team or for all (see Templates). When only Personal is available, the dropdown is not shown. The scope is set at creation.
Priority — a whole number from 0 to 1000 that determines the order of rules: the lower the number, the higher the priority (hover hint: Priority: a whole number from 0 to 1000, lower comes first). The default is 100. If several rules claim a single ad, the rule with the lower number runs first. A number outside this range, or text that is not a number, is refused on save with a red line under the header.
Enabled / Disabled — a toggle; its caption shows the current state. Only active rules take part in the check. A disabled rule is saved but does not trigger — convenient while you are still refining it.
desc — an arrow button that expands the Description field (it shows the hint What this rule does (optional)). Free text: what the rule does and why. Optional, but helps colleagues and your future self.
JS code (function checkAd(ad)) — the body of the rule in the central editor. Required to save. If you may edit the rule but not its code, the editor is read-only and a line above it says Only the rule's author or an administrator can edit its code. Inside the function you have access to:
- the ad fields
ad.*(spend, deposits, ROAS, geo, etc.) — the full list is on the Macros tab; - actions — pause and resume (see Actions).
A minimal example — pause the ad for a day if over 24 hours there is spend but no deposits:
/** @param {Ad} ad */
function checkAd(ad) {
if (ad.deps_total === 0 && ad.spend_24h > 100) {
pauseAd('24h', 'no deps with spend > 100');
}
}
Here pauseAd('24h', 'reason') pauses the ad itself for 24 hours. You can also pause an adset (pauseAdset(...)) and a campaign (pauseCampaign(...)). The full list of actions, call formats and pause types — in the Actions section.
The function must be named exactly checkAd and take a single parameter ad. Apart from it, there must be nothing at the top level of the rule — not even a stray ; after the function: declare helpers and values inside checkAd. This is where a rule differs from a script, which can keep its helpers next to main(). Do not delete the line /** @param {Ad} ad */ above the function — it enables hints for the ad.* fields right in the editor.
Not sure of a field name? Open the Macros tab and use the search by name or description. The fields are grouped: ad, creative, offer, geo, network and metrics for the previous period.
If a rule does not save
The reason appears as a red line under the editor header. The fields are checked first, and these reasons are in your interface language: a rule without a name will not save (Name is required), and neither will one without code (JS code is required); an administrator creating a team rule has to pick the team (Select a team).
Then the server checks the code itself. The server writes its reasons in English and Russian only: with Russian as the interface language they come in Russian, with any other language — in English, as in the table below. The Test tab goes through the same checks: with a wrong code shape the test does not start and names the same reason.
| Reason | What to fix |
|---|---|
"The rule code is empty. Write function checkAd(ad) { ... } in it." | the code holds only comments — write the checkAd function |
| "Only the checkAd(ad) function may sit at the top level of a rule, but there are 2 statements. …" | remove everything except checkAd from the top level; move helpers and values inside it |
"Only the function checkAd(ad) { ... } declaration is allowed at the top level of a rule." | the top level holds something other than a function declaration — for example, const checkAd = (ad) => …; declare the function with the word function |
| "The rule's function must be named checkAd, not foo." | rename the function to checkAd |
| "checkAd must take exactly one parameter: ad." | leave the function a single parameter, ad |
| "The rule calls "pauseAdd", which does not exist: …" | the code calls a function that does not exist — most often a typo in the name; if there are several such calls, the first of them and the total count are named |
| "The rule code does not parse: …" | a mistake in how the code is written; after the colon — its description and location, in English whatever the interface language. The rule code is compiled in JavaScript strict mode, so a refusal can also come on code that non-strict mode would let through — for example, on the number 010 |
| "The server is busy checking other code right now, so this rule was not checked. Try again a little later." | the server was busy — save the rule again |
A rule without code will not save through the Qubix programmatic interface either (see MCP/API): both a create without code and an edit that would erase the code are refused.
What appears after creation
A saved (already existing) rule has two tabs available below the editor:
- Held — the ads that this rule is currently holding on pause. Next to it — a counter of their number.
- Action history — the log of all triggers of the rule: when, for which ad and what was done.
A new, not-yet-saved rule does not have these tabs — they appear after the first save.
The Held table has three columns:
- Ad ID — the ad identifier;
- Expires — when the ad returns to work: the time left until the return, or one of the words — while matches (a pause with no term: the ad returns on its own as soon as the condition stops being met), permanent (the ad does not come back on its own), expired (the term ran out while the page was open; the ad returns on the nearest check pass);
- Since — when the pause was set.
When the rule holds nothing, the tab says No ads on hold.
The Action history table has these columns, and a search by Ad ID above it:
- Time — when the rule triggered. Triggers that repeat unchanged one after another are collapsed into one row: the time of the last one stands first, and under it the line since … (the time of the first one stands in place of the ellipsis);
- Ad ID — the ad identifier;
- Repeats — how many times the trigger repeated, written as
×and the number; a dash when it happened once; - Action — what was done: pause or activate (return to work);
- Note — an extra note about the result, for example the text of a Facebook error; a dash if there is none. It is the same value as in the Note column of the Trigger logs.
Delete (the item in the ⋮ menu in the top-right corner of the editor; it is there only for a saved rule that you may edit) does not erase history: the rule is moved to the disabled state, and the log of its triggers is kept. Before that the editor asks to confirm: Delete rule "…"? The history is kept. (the rule name stands in place of the ellipsis). But you cannot restore the rule itself back to active in a single click — act deliberately.
If you open a rule that does not exist or is not visible to you — for example, by a link to a deleted rule — the page says Rule #… not found (the rule number stands in place of the ellipsis) and offers the Back to list button.