How Hook works
You can use Hook well without reading this page. Read it when you want to know why an answer is what it is, why a question costs what it costs, or what Hook does and does not do on your behalf.
A question is a small, plain description
Everything you build in the builder is saved as a small description of the question, called the query. It holds the conditions, the output, the sub-hooks, and also your names, notes, collapsed blocks and spacing. It holds no data and no site.
- In the builder it is what you edit. In a Copy link it sits in the address, so the link reopens the exact question.
- Whoever opens a link runs it against their own current site. Your site is never in the link.
- A query from anywhere (a link, the code panel) is treated as untrusted. It is upgraded to the current format, then checked for size and structure, then checked for types, on every run.
- Queries are versioned. When Hook changes, old links are upgraded step by step and keep working, and Hook tells you when it did that.
What happens when you press Run
- Who and which site. The server works out who you are and which site you are looking at, exactly as every page in the dashboard does. The browser is never asked to name a site.
- Upgrade and check. An older query is upgraded; the query is checked against the limits and types.
- Sub-hooks first. Every sub-hook runs once, inside the database, and its result is held ready for the hook above it.
- Estimate. Hook asks the database how many rows each top-level step would keep. This is a planning question answered from the statistics the database already holds, so no visitor data is read.
- Plan and cost. Hook decides the order, works out the credits, and compares them with your limit.
- Run. If the cost is within the limit, the database runs the whole question in one statement.
- Answer and account. The answer comes back with how it was found: the order, what each sub-hook carried, the cost and the timings.
Steps: one pass or step by step
The top-level conditions are the steps of a question. When their sizes are very different, Hook runs the smallest first and each next step only checks what survived. When they are similar, it runs them together and the database orders them itself. Either way the answer is identical; only the speed differs.
If you set the order by hand and it would be at least 10 times slower, Hook runs the faster order and tells you, unless you switched that safeguard off. An estimate can be wrong when conditions are correlated or when a measure over connected rows is rough, and a wrong estimate costs speed, never correctness.
Connected rows and tunnels, precisely
Connected rows
A connected-row condition looks at rows linked by the identifiers the tracker records (session, visitor, page address). Its conditions apply to the same row together. A count or total is measured over exactly the connected rows that match.
Tunnels
- A sub-hook runs once. Its result never travels to the browser and back, so its size does not change the cost the way manual copying would.
- One value feeds comparisons; a list feeds is any of and is none of. Types must match. Breaking a rule is an error naming both sides, never a silent conversion.
- Sub-hooks can nest, and the depth is capped.
Credits and cost
The cost is known before anything runs. Hook asks the database for its own estimate of the work in the exact statement it is about to run, and converts that into credits, with a minimum of 1. If the estimate is over your limit, nothing runs. Because the estimate is for the real statement, the cost you are shown is the cost you pay.
| What lowers the cost | Why |
|---|---|
| A narrow first condition | Later steps only look at what survived. |
| Sub-hooks | Computed once per run, however many rows read them. |
| Conditions before measures | Measures over connected rows are cheap on a filtered set and expensive as the first step over a whole site. |
Safety
- One site only. The site comes from the server, never from the query. Every table in the statement is pinned to it.
- Read only. Hook runs through a database login that can read, not write.
- Values are never pasted into the statement. Every value you type is passed separately, so text cannot change the meaning of a question.
- A run is stopped after 8 seconds so a heavy question cannot hold the database.
- Errors tell you what to change. Server problems show only a short reference code; the details stay in the server log.
What is kept
| What | Where | How long |
|---|---|---|
| Step size estimates | Server memory | 5 minutes |
| Value suggestions (pages, campaigns, countries) | Fetched when you choose a field | Per page load |
| Answers | Not kept | Every run is live |
| The query | The address bar | As long as the link exists |
Nothing runs on its own. Every run is started by a person, because every run is metered.
Definitions Hook relies on
| Term | Definition |
|---|---|
| Page | A page address of your site, as recorded for the page view. |
| Converted session | A session that has a form submission. |
| Lead | A form submission. Its visitor is the browser that submitted it. |
| Time on page | Left at minus entered at, both stamped by our server. This is the figure session replay shows. The browser timer is a separate field. |
| Away period | The time between one page view ending and the next starting in the same session, when it is 15 seconds or more. The same rule session replay uses for its away bars. |
| Share of page seen | The share of the page that was on screen, from the recorded scroll positions and screen height. Empty, never guessed, when the screen height was not recorded. |
| Hours and weekdays | UTC. |
Limitations today
- Custom form answers are not available as fields in conditions yet.
- The referrer is raw text; the classified traffic source is not a field yet.
- Hours and weekdays are UTC, not the visitor's local time.
- Share of page seen uses where the visitor entered, went deepest, and scrolled back to. The session replay chart can show finer detail.
- Very large questions make long links. Saved hooks will remove this.
The developer guides live in the repository under jh-hook/: architecture, data flow, the field reference and the decision log.