Difference between revisions of "Retrieving query string parameter values using JavaScript"
From Market Ruler Help
(Created page with '<span class="code">__CR.query</span> is a function which takes two parameters and retrieves the string value of the query string parameter.') |
|||
Line 1: | Line 1: | ||
<span class="code">__CR.query</span> is a function which takes two parameters and retrieves the string value of the [[Query_string#Query_String|query string]] parameter. | <span class="code">__CR.query</span> is a function which takes two parameters and retrieves the string value of the [[Query_string#Query_String|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 <span class="code"><nowiki>http://www.example.com/landing/?Source=ppc&product_id=6238751238&s=home+remedy</nowiki></span>: | ||
+ | |||
+ | <script> | ||
+ | __CR.query("Source"); # value is "ppc" | ||
+ | __CR.query("product_id"); # value is "6238751238" | ||
+ | __CR.query("s"); # value is "home remedy" | ||
+ | __CR.query("campaign", "default campaign"); # value is "default campaign" | ||
+ | </script> | ||
+ | |||
+ | Using this within the tracking calls would be, for example: | ||
+ | |||
+ | <script> | ||
+ | __CR.track("contact", null, __CR.query("email", "-no-email-")); | ||
+ | </script> | ||
+ | |||
+ | == See also == | ||
+ | |||
+ | * [[:Category:ConversionRuler JavaScript Functions]] | ||
+ | * [[__CR.cookie]] | ||
+ | |||
+ | [[Category:ConversionRuler]] | ||
+ | [[Category:ConversionRuler JavaScript Functions]] |
Revision as of 18:31, 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:
<script> __CR.query("Source"); # value is "ppc" __CR.query("product_id"); # value is "6238751238" __CR.query("s"); # value is "home remedy" __CR.query("campaign", "default campaign"); # value is "default campaign" </script>
Using this within the tracking calls would be, for example:
<script> __CR.track("contact", null, __CR.query("email", "-no-email-")); </script>