Skip to main content

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, or EXPLAIN are 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 ROLES and 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 (render whose target_type is not offer_redirect, url_redirect, tg_channel or tg_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 with push_ stays in qubix_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.

SQL
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​

ColumnWhat it is
eventThe event type (values in the table below)
event_timeThe event time
piuidThe visitor id (persistent across visits)
pwa_idThe PWA the event belongs to
domainThe domain the event happened on
urlThe page address

Geo and device​

ColumnWhat it is
geo, countryThe visitor's country (by GeoIP)
cityThe city
languageThe browser language
uaThe User-Agent
ipThe IP address
deviceDevice data (JSON)

Tracking and attribution​

ColumnWhat it is
click_idThe tracker click id
campaign_idThe tracker campaign
ad_idThe ad
sub_id_1 … sub_id_16Custom tracker tags
fbc, fbp, fbclidFacebook attribution parameters
gclid, gbraid, wbraid, ttclidGoogle / TikTok attribution; gbraid and wbraid are the marks Google puts on an iPhone click in place of gclid
source_clidThe 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
pixelThe pixel id
paramsAll address parameters (a "key → value" map)

Offer​

ColumnWhat it is
offer_idThe offer
offer_urlThe offer link

Push​

Filled on the rows of qubix_push_events.

ColumnWhat it is
push_campaign_idThe push campaign
subscription_idThe visitor's push subscription
message_idThe sent message id
push_title, push_bodyThe push text

Conversion​

ColumnWhat it is
statusThe conversion status
revenueThe revenue for the event
revenue_usdThe revenue in US dollars, converted when the conversion arrives. Reports count revenue and deposits by this column, not by revenue
currencyThe currency
response_codeThe response code (for server-side events)
error_messageThe error text, if any
external_idAn external identifier
extraExtra event data (JSON)
editionEmpty 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:

GroupValuesTable
Visitscampaign_visit, render of a target that sends the visitor straight onqubix_events
Server recordswhite_page, crawler_visit, every other renderqubix_server_events
PWA installinstall_accepted, install_rejected, install_blocked, installed, launch_pwa, install_fallback_redirectqubix_events
Pushpush_prompt_shown, push_allow, push_deny, push_ignored, push_subscribe, push_sent, push_shown, push_click, push_dismiss, push_expired, push_failedqubix_push_events
Conversionsreg (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:

JavaScript
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​

TableWhat's inside
pwa_appsPWA app settings: pwa_id, name, status, country, category, rating, downloads, push_placement, and other constructor fields
push_subscriptionsPush subscriptions: subscription_id, pwa_id, geo_country, active, subscribed_at
push_campaignsPush campaigns: push_campaign_id, name, status, target_geo
v_deposits_min_revenueThe 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.

Caution

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.

What's next​