Sub-hooks and tunnels
The most powerful part of Hook. A sub-hook is a whole question whose answer becomes a value inside another question. The tunnel is that flow. It replaces copying a result from one report into the next.
Why you would use one
Some questions have two steps: "find these people, then look at what they did". Without a sub-hook you would run one question, copy its answer, and paste it into a second. With a sub-hook it is a single question, and Hook runs it in one go.
How to add one
- Next to any value, choose the result of a sub-hook (tunnel) instead of a value I type.
- A full hook builder opens inside a dashed box. Build it exactly like any other question.
- Look at the box border. It says Fits in green, or the reason in red.
A sub-hook can contain sub-hooks of its own. The innermost one runs first.
What fits where
Two rules decide whether a sub-hook can feed a value. Hook enforces both and never converts silently.
| Rule | Meaning |
|---|---|
| Shape | A sub-hook returning one value (a count or a calculation) fits any single-value comparison, such as "more than". A sub-hook returning a list fits only is any of and is none of. |
| Type | The kinds must match. A list of visitor ids fits a visitor id field. A count cannot feed a duration. |
- If you used a comparison with a list, the box turns red and offers Use "is any of" instead. One click fixes it.
- A breakdown hands over its keys. "The 5 pages with the most views" becomes a list of 5 pages.
- Sub-hooks offer every output the main hook has: a number, a calculation, a list, values or a breakdown.
Turning a hook into a sub-hook
Sometimes you build a question and then realise it should feed a bigger one. Press Use this hook as a sub-hook... under the main hook. Your whole hook moves inside a new one, you pick where its result should flow, and Hook offers only the places it fits.
Seeing what a sub-hook did
- The preview draws each sub-hook as a smaller figure under "Sub-hooks, flowing in through tunnels", saying which value it flows into.
- How it ran reports what each tunnel carried: one value, or a count and the first few values.
A sub-hook runs once, inside the database. Its result never travels to your browser and back, so a tunnel carrying fifty thousand ids still costs one run. Copying and pasting a list of that size by hand would not even be possible.