Retrieving query string parameter values using JavaScript

From Market Ruler Help
(Redirected from CR.query)
Jump to: navigation, search

__CR.query is a function which takes two parameters and retrieves the string value of the query string parameter.

__CR.query = function (name, default_value) { ... }

The name is the exact name of the query string variable to retrieve. The default value is returned (or null if no default is supplied) if the query string is not found in the current page URL.

Examples will explain its usage best. While visiting the page:

The following code would result in the following values:

__CR.query("Source", "-no-source-");          # value is "ppc" (String)
__CR.query("source", "-no-source-");          # value is "-no-source-" (String)
__CR.query("product_id");                     # value is "6238751238" (String)
__CR.query("s");                              # value is "home remedy" (String)
__CR.query("campaign");                       # value is null
__CR.query("campaign", 12);                   # value is 12 (Number)
__CR.query("campaign", "default campaign");   # value is "default campaign" (String)

Using this within the tracking calls would be, for example:

__CR.track("contact", null, __CR.query("email", "-no-email-"));

See also