Difference between revisions of "Retrieving query string parameter values using JavaScript"

From Market Ruler Help
Jump to: navigation, search
Line 5: Line 5:
 
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.
 
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 <span class="code"><nowiki>http://www.example.com/landing/?Source=ppc&product_id=6238751238&s=home+remedy</nowiki></span>:
+
Examples will explain its usage best. While visiting the page:
 +
 
 +
<nowiki>http://www.example.com/landing/?Source=ppc&product_id=6238751238&s=home+remedy</nowiki>
 +
 
 +
The following code would result in the following values:
  
 
  <script>
 
  <script>
  __CR.query("Source");                         # value is "ppc"
+
  __CR.query("Source", "-no-source-");         # value is "ppc" (String)
  __CR.query("product_id");                    # value is "6238751238"
+
__CR.query("source", "-no-source-");          # value is "-no-source-" (String)
  __CR.query("s");                              # value is "home remedy"
+
  __CR.query("product_id");                    # value is "6238751238" (String)
  __CR.query("campaign", "default campaign");  # value is "default campaign"
+
  __CR.query("s");                              # value is "home remedy" (String)
</script>
+
__CR.query("campaign");                      # value is null
 +
__CR.query("campaign", 12);                  # value is 12 (Number)
 +
  __CR.query("campaign", "default campaign");  # value is "default campaign" (String)
 +
  </script>
  
 
Using this within the tracking calls would be, for example:
 
Using this within the tracking calls would be, for example:

Revision as of 18:33, 30 June 2016

__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:

http://www.example.com/landing/?Source=ppc&product_id=6238751238&s=home+remedy

The following code would result in the following values:

<script>
__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)
 </script>

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

<script>
__CR.track("contact", null, __CR.query("email", "-no-email-"));
</script>

See also