URL data handling

Query params

Read the URL the respondent arrived on. `request.url` is the raw entry URL; `request.param("key")` reads a single query string value. Use it for panel-supplied IDs, source codes, language hints, pre-fill tokens, anything the host can pass in.

What request is

request is a runtime proxy that’s always in scope inside any expression the runtime evaluates — validation: blocks, - script: blocks, inline if: conditions, options.from: expressions, piped {{ }} placeholders. Two members:

MemberReturnsMeaning
request.urlstringThe raw entry URL the respondent arrived on. Empty string "" when the host didn’t supply one (e.g. preview without a URL).
request.param("key")stringThe value of query-string parameter key. Empty string "" when the key isn’t present.

That’s the whole surface. There’s no request.params collection, no request.has(key), no request.method, no request.headers. The two everyday handles are enough — request.url for the rare case you need the full URL, request.param(...) for everything else.

request.param("key") — read one value

The everyday call. Pass a key, get the URL-decoded string value. Use it inside a - script: to capture the value into a hidden question, or directly inside an if: / {{ }} / validation: expression.

- qid: QSource
    type: open
    visibility: hide
    text: Source code captured from the entry URL's ?source param

- script: |
    QSource.set(request.param("source"))

If the respondent arrived at ?source=panelA, the script writes "panelA" into QSource, where it lands in the export. The runtime URL-decodes the value automatically, so ?source=panel%20A resolves to "panel A".

Empty string for missing keys

When the key isn’t in the URL, request.param returns the empty string "" — never None/null. Read the value into a local variable inside a - script:, normalise it however you need, then act on it:

- script: |
    source = request.param("source").lower()

    # Wrong — request.param() never returns None.
    # if source is None: ...

    # Right — check against an empty string.
    if source == "":
        hSourceMissing.set(1)

    # Cleaner — empty strings are falsey.
    if not source:
        hSourceMissing.set(1)

This matters for screening rules and conditional branches: a missing param doesn’t blow up your expression, it just compares equal to "". Decide whether that should count as “absent” or “present-but-blank” yourself, and do the decision inside a script — you get a real Python block, real local variables, and the chance to normalise the value (lowercase, trim, etc.) before anything reads it.

Case-sensitive keys

Keys are matched case-sensitively. request.param("Source") and request.param("source") are two different lookups. Pick a casing convention with whoever’s building the entry URLs and stick to it (lowercase is the safe default).

request.url — the raw entry URL

When you need the full URL — typically because you’re forwarding the respondent on with the URL preserved, or logging which landing page they came from — request.url is the raw string.

- script: |
    hEntryUrl.set(request.url)

It’s read-only: there’s no request.host, request.path, or request.query. If you need a part, parse it yourself with the re module or write a script helper.

In preview without a supplied URL, request.url is "". In production it’s whatever URL the platform host passed in when the interview started.

Where you can use request.*

The proxy is attached to every runtime evaluation context, so the same expressions technically work everywhere an expression lives. In practice, read URL params inside a - script: block — capture, normalise, and store them into hidden questions once at the top of the flow, then have the rest of the survey read those hidden questions instead of poking at request.* directly.

The reasons to centralise in a script:

  • Real Python. You get local variables, .lower() / .strip(), if-elif chains, and the chance to normalise once.
  • Empty-string footgun. request.param(...) returns "" for missing keys, not None. Outside a script that distinction is easy to forget; inside a script it’s obvious.
  • Single source of truth. A hidden question that holds the normalised value can be referenced from if:, validation, piping, and routing — all the downstream sites stay consistent.
Use siteRecommended?Example
- script:Yes — primaryQSource.set(request.param("source").lower())
Inline if:Supportedif: request.param("source") == "panelA"
- if <expr>: flow blockSupported- if request.param("lang") == "es":
validation:Supportedinside the Python block, treat request.param("rid") like any string
Piped {{ }}Supportedtext: Hi {{ request.param("name") }}, welcome.

Reach for the supported sites when a single one-off check would be overkill to lift into a script — but the moment two places read the same param, push it through a hidden question instead.

Common patterns

Capture a query param into a hidden question

The most common use — the entry URL carries identifying info, you echo it into a hidden question so it lands in the export. Declare the hidden question, then write the value with a - script: near the start of the flow.

- qid: QPanelId
    type: open
    visibility: hide
    text: Panel-supplied respondent ID from the entry URL's ?panelid param

- qid: QSource
    type: open
    visibility: hide
    text: Traffic source code captured from the entry URL's ?source param

- script: |
    QPanelId.set(request.param("panelid"))
    QSource.set(request.param("source"))

Both questions render hidden, but their values are written by the script and fall into the export alongside the rest of the answers.

Branch on a panel-supplied source code

- if request.param("source") == "panelA":
    - qid: QPanelAOnly
        type: single
        text: Question only panel-A respondents see.
        options:
            1: Yes
            2: No

- elif request.param("source") == "panelB":
    - qid: QPanelBOnly
        type: open
        text: Free-text question only panel-B respondents see.

Same shape as any - if: branching — the condition just reads from the URL instead of an earlier answer. See Routing.

Set a respondent’s language from ?lang=...

- script: |
    if request.param("lang") == "es":
        hLanguage.set("es")
    elif request.param("lang") == "fr":
        hLanguage.set("fr")
    else:
        hLanguage.set("en")

Capture the URL’s language hint into a hidden question you’ve defined for the survey’s locale state. Default to English when the param is missing or unrecognised.

Validate a panel ID format

Read the URL value once, validate the shape, terminate the interview if it’s wrong:

- qid: QPanelId
    type: open
    visibility: hide
    text: Validated panel respondent ID from the entry URL's ?rid param

- script: |
    rid = request.param("rid")
    if not re.fullmatch(r"[A-Z0-9]{8,16}", rid):
        endSurvey("terminate")
    QPanelId.set(rid)

Even though the param comes from a trusted panel partner, a respondent could hand-edit the URL. Treat anything that comes through request.param(...) as untrusted input and validate it before you act on it. See Survey status & redirect for endSurvey(...).

Capture UTM params for export

- qid: QUtmSource
    type: open
    visibility: hide
    text: Campaign source captured from ?utm_source (e.g. google, newsletter)

- qid: QUtmMedium
    type: open
    visibility: hide
    text: Campaign medium captured from ?utm_medium (e.g. email, cpc, social)

- qid: QUtmCampaign
    type: open
    visibility: hide
    text: Campaign name captured from ?utm_campaign (e.g. spring_launch_2026)

- script: |
    QUtmSource.set(request.param("utm_source"))
    QUtmMedium.set(request.param("utm_medium"))
    QUtmCampaign.set(request.param("utm_campaign"))

A standard pattern for surveys promoted across multiple campaigns: each UTM tag lands in its own hidden question and falls into the export verbatim. Place the - script: once near the top of the survey so the values are captured before any question references them.

Trust boundary — never trust a query param

request.param(...) returns whatever the URL says. A respondent can edit the URL bar; a panel partner can pass the wrong value; a marketer can mistype a UTM tag. Treat every query-param value as untrusted input:

  • Validate format before you branch on it (regex, allow-lists).
  • Don’t use it as authentication — knowing a panel ID isn’t proof of being that panellist.
  • Pin sensitive logic to server-side state (quota state, real qualification rules) rather than to a URL param the respondent could rewrite.

Host-supplied params override URL params

The host platform can also inject params via an out-of-band mechanism (the request.params hand-off the runtime accepts). When both an out-of-band param and a URL param share a key, the out-of-band value wins.

In practice this matters when a panel platform passes a respondent ID through a backchannel and also through the URL — the backchannel value is the canonical one. Authors don’t have to do anything special; request.param("rid") returns the authoritative value either way.

See also

  • Survey status & redirect — endSurvey(...) and redirectUrl(...) accept request.param(...) values straight through to the redirect target
  • Routing — - if: and if: branches accept request.param(...) like any other expression
  • Scripts — - script: blocks for capturing params into hidden questions on entry
  • Piping — {{ request.param("...") }} works inside any pipe-aware text field