Tables for sql queries
The sql`…` command is part of the Server SDK: it reads data straight from the
Qubix database and is available in scripts,
Britva auto-rules, and landing page handlers. This is a
reference for which tables and columns you can reach, and by what rules.
How access works
- Read-only. Only queries that start with
SELECT,WITH,SHOW,DESCRIBE, orEXPLAINare allowed. Any data changes (INSERT,UPDATE,DELETE) and reaching out to external sources from inside the query are blocked. - No questions about the database account. A query that asks which database account it runs under —
currentUser()and the other account functions,SHOW GRANTS,SHOW CURRENT ROLESand the like — is refused with an explanation. - Safe parameters. Values passed through
${…}always go as query parameters, not spliced into the text. You do not escape anything by hand, and query substitution is impossible. - You see only your own data. The query runs within your role's permissions: you get exactly the rows you are allowed to see in reports. Other people's data is not reachable.
- A size limit. A single query returns at most a few thousand rows (the administrator
sets the exact cap). For large selections, aggregate right in the query —
count(),sum(),GROUP BY.
The table name is written without a database prefix — just qubix_events.
qubix_events — the event stream
The main table: one row per visitor event and per conversion action. Through it you can see what happens to the traffic — from the first visit to the deposit.
Two more tables have exactly the same columns:
qubix_server_events— the records the server keeps of its own answers: the safe page the cloak served (white_page), a crawler's visit (crawler_visit) and a page the server gave out without sending the visitor on (renderwhosetarget_typeis notoffer_redirect,url_redirect,tg_channelortg_bot). Its rows are kept for 30 days unless the administrator sets another period;qubix_push_events— the events of push notifications, from the permission prompt to the click:push_prompt_shown,push_allow,push_deny,push_ignored,push_subscribe,push_sent,push_failed,push_expired,push_shown,push_click,push_dismiss. Your own event whose name merely starts withpush_stays inqubix_events.
To read a visitor's whole history, put the tables together with UNION ALL, and in the qubix_events branch keep only its own
rows: for a while after an update the moved rows lie in both tables.
SELECT event, event_time FROM qubix_events WHERE piuid = '<piuid>'
AND NOT (event IN ('white_page', 'crawler_visit') OR (event = 'render' AND target_type NOT IN ('offer_redirect', 'url_redirect', 'tg_channel', 'tg_bot')) OR event IN ('push_prompt_shown', 'push_allow', 'push_deny', 'push_ignored', 'push_subscribe', 'push_sent', 'push_failed', 'push_expired', 'push_shown', 'push_click', 'push_dismiss'))
UNION ALL SELECT event, event_time FROM qubix_server_events WHERE piuid = '<piuid>'
UNION ALL SELECT event, event_time FROM qubix_push_events WHERE piuid = '<piuid>'
Event and identity
| Column | What it is |
|---|---|
event | The event type (values in the table below) |
event_time | The event time |
piuid | The visitor id (persistent across visits) |
pwa_id | The PWA the event belongs to |
domain | The domain the event happened on |
url | The page address |
Geo and device
| Column | What it is |
|---|---|
geo, country | The visitor's country (by GeoIP) |
city | The city |
language | The browser language |
ua | The User-Agent |
ip | The IP address |
device | Device data (JSON) |
Tracking and attribution
| Column | What it is |
|---|---|
click_id | The tracker click id |
campaign_id | The tracker campaign |
ad_id | The ad |
sub_id_1 … sub_id_16 | Custom tracker tags |
fbc, fbp, fbclid | Facebook attribution parameters |
gclid, gbraid, wbraid, ttclid | Google / TikTok attribution; gbraid and wbraid are the marks Google puts on an iPhone click in place of gclid |
source_clid | The click mark: the ad platform's click id; for a visit of a traffic source without one, the source's click id after the source's fingerprint (a 16-character code derived from its id), else the event's own id |
pixel | The pixel id |
params | All address parameters (a "key → value" map) |
Offer
| Column | What it is |
|---|---|
offer_id | The offer |
offer_url | The offer link |
Push
Filled on the rows of qubix_push_events.
| Column | What it is |
|---|---|
push_campaign_id | The push campaign |
subscription_id | The visitor's push subscription |
message_id | The sent message id |
push_title, push_body | The push text |
Conversion
| Column | What it is |
|---|---|
status | The conversion status |
revenue | The revenue for the event |
revenue_usd | The revenue in US dollars, converted when the conversion arrives. Reports count revenue and deposits by this column, not by revenue |
currency | The currency |
response_code | The response code (for server-side events) |
error_message | The error text, if any |
external_id | An external identifier |
extra | Extra event data (JSON) |
edition | Empty on most rows. When one conversion is caught twice — by the page's code and by the partner's postback — the postback's row carries postback, and a copy of the page's row carrying cancel cancels the page's row. Count conversions with sum(if(edition = 'cancel', -1, 1)) instead of count(), and their revenue with sum(revenue_usd * if(edition = 'cancel', -1, 1)) |
event values
The main event types you'll see in the stream:
| Group | Values | Table |
|---|---|---|
| Visits | campaign_visit, render of a target that sends the visitor straight on | qubix_events |
| Server records | white_page, crawler_visit, every other render | qubix_server_events |
| PWA install | install_accepted, install_rejected, install_blocked, installed, launch_pwa, install_fallback_redirect | qubix_events |
| Push | push_prompt_shown, push_allow, push_deny, push_ignored, push_subscribe, push_sent, push_shown, push_click, push_dismiss, push_expired, push_failed | qubix_push_events |
| Conversions | reg (registration), dep (deposit) | qubix_events |
The subscribe and install event values match the Browser SDK events — what
window.sdk sends from the browser lands in these tables.
Example
How many visitors from each country allowed push in the last day:
const rows = sql`
SELECT geo, count() AS allowed
FROM qubix_push_events
WHERE event = 'push_allow'
AND event_time >= now() - INTERVAL 1 DAY
GROUP BY geo
ORDER BY allowed DESC`
for (const row of rows) console.log(row.geo, row.allowed)
Other tables
| Table | What's inside |
|---|---|
pwa_apps | PWA app settings: pwa_id, name, status, country, category, rating, downloads, push_placement, and other constructor fields |
push_subscriptions | Push subscriptions: subscription_id, pwa_id, geo_country, active, subscribed_at |
push_campaigns | Push campaigns: push_campaign_id, name, status, target_geo |
v_deposits_min_revenue | The deposit threshold: one row with the threshold column. A dep event counts as a deposit when its revenue_usd is above it; the value is set by the Minimum revenue of a real deposit field, see Reports |
Ready-made report metrics (spend, revenue, ROAS, per-ad conversions) are easier to take not
from the raw stream but from the ad object's fields — the full list is in
Metrics and columns.
Service secrets are not reachable from queries — for example, the private keys for push cannot be read. A query always works read-only and only within your role's permissions.