The getQueryParameterByName extension reads a query parameter from the current page URL and returns the matching value. It is useful when a journey needs to verify that an application action has updated, added, or preserved a specific query-string value.
This is useful when testing filters, redirects, tracking parameters, deep links, campaign links, pagination, search pages, or any workflow where the expected result appears in the browser URL rather than directly on the page.
Parameters:
-
namerequired, the query parameter name to search for in the current page URL. Pass the parameter name only, without the leading?or&characters;
Note: The extension reads from window.location.href at the moment the step runs. It returns the decoded parameter value, an empty string when the parameter exists without a value, or null when the parameter is not present.
How to apply this to your journey
Use the extension in a journey by calling getQueryParameterByName with the execute command. Pass the query parameter name to the name input and store the returned value in a variable.
Note: Run this step after the journey has navigated to the page or after the application action has finished updating the URL. If the page is a single-page application, add a suitable wait or assertion before reading the query parameter.
navigate to "https://www.google.com/?source=hp"
execute "getQueryParameterByName" using "source" as name returning $param
assert $param equals "hp"navigate to "https://example.com/products?category=shoes&page=2"
execute "getQueryParameterByName" using "page" as name returning $pageNumber
assert $pageNumber equals "2"You can also store the parameter name in a Virtuoso variable and pass that variable to the extension.
execute "getQueryParameterByName" using "$parameterName" as name returning $parameterValuestore value "source" in $parameterName
navigate to "https://www.google.com/?source=hp"
execute "getQueryParameterByName" using "$parameterName" as name returning $parameterValue
assert $parameterValue equals "hp"Example output when the current URL is https://www.google.com/?source=hp and the input name is source:
hpThis extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension reads only the URL available in the browser page context when the Virtuoso step runs. It does not inspect server-side redirects, network requests, browser history entries, URL fragments unless they appear after the query match, or query parameters from a different tab, window, iframe, or backend API call. The source code parses the query string with a regular expression and then decodes the result with decodeURIComponent after replacing + with a space, so encoded values are returned in decoded form and malformed percent-encoding can fail the step. If the same parameter appears multiple times, the first matching value is returned. Timing also matters: in single-page applications, client-side route changes, redirects, or delayed URL updates must complete before the extension runs. Cross-browser note: The extension uses standard browser APIs such as window.location.href, RegExp, and decodeURIComponent, but URL state can still vary across Chromium, Firefox, Safari, Edge, iOS, Android, and remote-grid executions when redirects, mobile routing, hash-based routing, or responsive application behavior differ. Validate it in each browser/device configuration used by your plan rather than assuming one default-browser run represents every platform.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 10/06/2026
Resources:
This extension does not require any external resource.
function getQueryParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
return getQueryParameterByName(name, window.location.href)
Comments
0 comments
Please sign in to leave a comment.