Util.getQueryParam
Query string parameters in a browser URL frequently contain important data for Analytics. Use the Util.getQueryParam()
method to retrieve data from the query string.
Get query string parameter data using the ÃÛ¶¹ÊÓƵ Analytics extension and Web SDK extension
You can get query string parameter data by setting values in data elements.
- Log in to using your ÃÛ¶¹ÊÓƵID credentials.
- Click the desired tag property.
- Go to the Data Elements tab, then click the desired data element (or create a data element).
- Set the Extension drop-down list to Core, and the Data Element Type to Query String Parameter.
- Enter the query string parameter in the text field.
The query string parameter value is stored in the data element. You can then reference the data element in rules to assign the desired variables.
s.Util.getQueryParam() in AppMeasurement and the Analytics extension custom code editor
Call the s.Util.getQueryParam()
method to retrieve a query string value from the browser URL. The string argument containing a query string parameter is required. This method returns a string, which you can assign to Analytics variables:
s.eVar1 = s.Util.getQueryParam("cid");
A second optional argument allows you to specify the string to check for query string parameters. By default, the utility looks at the browser URL.
// Search a custom string for query string parameter
var customString = "https://example.com?q=search";
// eVar1 is set to "search"
s.eVar1 = s.Util.getQueryParam("q",customString);
A third optional argument allows you to customize the query string delimiter. Its default value is &
. You can change this value if your query string uses a different delimiter.
var customString = "https://example.com?q1=value1;q2=value2;q3=value3";
// eVar1 is set to "value2"
s.eVar1 = s.Util.getQueryParam("q2",customString,";");
s.getQueryParam
is available. This plug-in contains more advanced features, but is also more complex and not included in AppMeasurement by default.