# Capture current and remembered query parameters

You can save a referral or campaign value from a visitor's URL, even if they leave the landing page before they submit your form.

Available on the Grow, Scale, and Pro plans.

Save the referral or campaign value that brought someone to your website, then use it in your flow or send it with a form. RightMessage can read the current page's URL or remember a value from an earlier page in the same browser.

You'll need the snippet installed on the pages you're using and access to edit your flow or form. To send the value to your email platform, connect a supported integration and choose a destination field that accepts it. Capturing a query value doesn't identify the visitor.

## Choose which value to save

Use `{{ query.ref }}` to read the current `ref` parameter, or its most recent remembered value if the current page doesn't have one. Use `{{ query.current.ref }}` if you only want the current page's value.

For example, someone could land on [WorkForge](https://workforge.rightmessage.com) at `https://workforge.rightmessage.com/?ref=workforge-guide`, then visit `/contact.html`. On the contact page, the current-only expression has no referral value. The remembered expression can still return `workforge-guide`.

The remembered value is the most recent occurrence, not the first visit's value or the most recent nonblank value. A URL ending in `?ref=` replaces an older referral with an empty string. `0` also counts as a present value.

The [Flow data and Liquid reference](https://rightmessage.com/help/flow-data-liquid-reference) explains the newest-to-oldest history lookup, the first-page fallback, and why `current` is a reserved name. The global data picker offers the current-page expression. Type the remembered expression directly, and keep the parameter name consistent across your links and expressions.

## Save it for later steps in your flow

A variable makes the value available before someone submits a form. It also lets you choose how long to keep it, rather than relying on the browser's page history.

1. On the flow canvas, choose **+** on a path before the final form or offer, then **Set Data**. On an empty canvas, use **Add the first step** instead.
2. Set **Action Type** to **Add / Update Variable**.
3. Enter `referral_source` in **Variable Name:**.
4. Enter `{{ query.ref }}` in **Variable Value:**.
5. Under **Expires:**, choose **In...**, then enter `7` and choose **Days**.
6. Choose **Done**.

![Set Variable action storing the remembered query.ref value as referral\_source for seven days](https://rightmessage.com/help/screens/verify-flows-query-capture.light.webp)

This saves the remembered referral for seven days. Each later assignment restarts that duration. **Expires:** defaults to **Never** if you don't change it. You can also choose a positive duration in **Minutes**, **Hours**, or **Weeks**.

A blank value removes the variable. If you use the current-only expression and want to keep an existing variable when the parameter is missing, put a condition before the assignment. Let it run only when the parameter is present.

Browser history isn't a permanent attribution record. Clearing browser data can remove the remembered referral, and another browser won't have the same history.

If you want the flow to update your email platform at this step, choose **Set Custom Field** instead and enter the expression in **Value:**. This is a separate action. A variable doesn't sync itself to your provider. Check that RightMessage can identify the visitor and that the destination record receives the update.

## Send it with a form instead

Use a hidden field when you want to send the value at submission, rather than use it in earlier flow steps. The visitor won't need to type anything.

1. Open the form's **Fields** tab.
2. Choose **Add field**.
3. Under **Layout & advanced**, choose **Hidden field**.
4. Select the destination custom field.
5. Enter `{{ query.ref }}` as the value, or `{{ query.current.ref }}` for the current page only.

![Hidden field inspector with blog-newsletter saved to the UTM Campaign field](https://rightmessage.com/help/screens/builders-form-hidden-field.light.webp)

The screenshot shows a fixed value. Replace it with your expression to capture each visitor's referral. The hidden field sends that literal or rendered value with the form. Select the destination yourself. The query parameter's name doesn't create a provider field, and the hidden field doesn't identify the visitor.

## Check it across page visits

Choose **Preview on your site** and test on your own pages with the snippet installed. In the same browser:

1. Open your landing page with `?ref=guide` added to its URL.
2. Visit another page without a query string.
3. Check that the current-only expression has no value and the remembered expression reads `guide`.
4. Return to the landing page with `?ref=workshop`. The remembered value should now be `workshop`.
5. Visit the page with `?ref=` and check that your blank-value handling does what you intended.

Repeat the missing-value check with fresh browser data. If you're sending the referral through a form, submit a test and inspect the destination contact record.

When the right value reaches your variable or contact field, review and [publish the draft](https://rightmessage.com/help/publishing-your-changes). Next, see how to [use variables in later steps](https://rightmessage.com/help/using-variables-in-flows).
