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

From Market Ruler Help
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 29: Line 29:
 
== See also ==
 
== See also ==
  
* [[:Category:ConversionRuler JavaScript Functions]]
+
* [[:Category:ConversionRuler JavaScript Functions|JavaScript Functions]]
 
* [[__CR.cookie]]
 
* [[__CR.cookie]]
  
 
[[Category:ConversionRuler]]
 
[[Category:ConversionRuler]]
 
[[Category:ConversionRuler JavaScript Functions]]
 
[[Category:ConversionRuler JavaScript Functions]]

Latest revision as of 19:08, 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