Skip to main content

Scripts

The Scripts section holds your own JavaScript programs that Qubix runs on a schedule or at the click of a button. A script gets access to ad data through a built-in set of commands (the QubApp SDK), can pause ads, turn them back on, submit to the reports the spend of platforms that have no export of their own into Qubix (the QubApp.submitSpend command), run read-only queries against the Qubix database (the sql command), read and change your own database (the Qubix.db command; which databases — Which databases), send its own Facebook requests through your browser profile (the fb command), call the tools of this Qubix installation — everything the panel does — with the rights of its owner (the QubApp.mcp command), reach out to external services and keep its own state between runs.

Scripts are a good fit when the standard Britva auto-rules are no longer enough: you need non-standard logic, a call to an external API, or calculations that are hard to express as a condition.

How scripts differ from Britva​

Both Britva and Scripts automate working with ads, but they solve different tasks.

Britva (auto-rules)Scripts
How the logic is describedA JavaScript condition over one ad (checkAd) → an action (pause/return)Free-form JavaScript code
Who it suitsAuto-pause/return of ads by a metric conditionNon-standard scenarios, your own logic
Database queriesYes, read-only SQL against the Qubix database (the sql command)Yes, read-only SQL against the Qubix database (the sql command)
Your own databaseNoYes, reading and writing (the Qubix.db command)
Submitting the spend of a platform without its own exportNoYes, on behalf of the script's owner (the QubApp.submitSpend command)
External servicesYes, a request to an external API (the global fetch function)Yes, a request to an external API (ctx.fetch)
Own Facebook requestsNoYes, any Facebook request — Graph API and other *.facebook.com addresses (the fb command)
Qubix tools — what the panel doesReading only, with the rights of the rule's owner (QubApp.mcp)Yes, reading and writing, with the rights of the script's owner (QubApp.mcp)
Memory between runsYes, the rule's own memory (ctx.state)Yes, its own state (ctx.state)
Entry barrierLower: only a condition (the AI assistant can write it)Higher: a whole program (the AI assistant can help)
Tip

If the task can be expressed as a simple condition "if ROAS is below the threshold — pause it", start with Britva auto-rules — it is faster and clearer. Use scripts where you need logic that a rule cannot express.

List of scripts​

The main screen of the section is headed Scripts. Under the heading is a table of all your scripts with the columns:

  • Name — the script name (if not set, a short identifier is shown). The built-in scripts carry the System mark next to the name.
  • Schedule — when the script runs automatically, as a readable phrase (for example, "Every 5 minutes"). A dash means no schedule is set, the script only runs manually.
  • Status — a check mark if the script is active; a dash if it is off. The column can be filtered by On and Off.
  • Last run — the time of the last execution and, in brackets, its result: executed when the run finished without an error, otherwise the word for the failure (see Run history). If the last run ended with an error, the text of the error appears when you hover over the cell. A dash means the script has not run yet.

The + Create script button in the top-right corner opens the editor for a new script. Clicking a table row opens an existing script for editing. Below the table the Samples block offers ready-made scripts to start from — see Samples.

Built-in scripts​

Every Qubix installation carries two built-in scripts, marked System in the list. Both are switched on by default and run on a schedule of their own:

  • Offer cap control, every 5 minutes. In the card its description reads: System script: pauses an offer when its deposits reach its cap. Split traffic is redistributed to the remaining offers.
  • Pause ads without live offers, every 2 minutes. In the card its description reads: System script: pauses Facebook ads whose campaign has no live offer left, and resumes them when an offer is available again.

A built-in script cannot be deleted: its card has no Delete item, and it is only switched off with the Active toggle. Its name and description are shown in the language of the panel for as long as nobody has edited them.

Samples​

The Samples block stands under the table of scripts. Each sample is a card with a name, a short description and the Copy to my scripts button. Above the cards the block explains what a copy is: A copy becomes your own script: edit it however you like — our updates to the sample no longer touch it. It arrives disabled; read the thresholds in its text before switching it on. If the samples could not be loaded, the block is not shown at all.

The sample available on every installation is Raise the budget of profitable campaigns: Finds campaigns whose return is above a threshold and raises their daily budget by a set share. The return threshold, the raise step, the money ceiling and the cooldown between changes all live in the script's text — tune them to your own.

Where the QubDesk section is shown, the block also carries four samples of task rules (see Task rules):

  • Assigning an assignee to new tasks: An event rule: a new task without an assignee goes to the person named in the script's text.
  • Handing a task over on a status change: An event rule: a task that moves into a status from the list in the script's text goes to the person named there, and a comment is written in it.
  • Ban on closing a task without an assignee: A transition check: a task without an assignee cannot be moved into the statuses named in the script's text; the person sees the reason.
  • Reminder about overdue tasks: On schedule: a comment in overdue open tasks, at most once a day per task.

How to take a sample:

  1. Read the description of the sample and click Copy to my scripts. While the copy is being made, the button reads Copying…, and the buttons of the other samples are not available.
  2. Qubix creates a new script in your name, called like the sample, and opens its card.
  3. Read the text of the script: the thresholds and the limits of the sample are written in the code itself. The copy comes switched off and with no schedule, so nothing happens until you switch it on with the Active toggle and set a schedule.

The copy is your own script: edit it as you like, later changes of the sample do not reach it.

What's next​