Difference between revisions of "CR.cookie"
(Created page with '<span class="code">__CR.query</span> is a function which takes two parameters and gets or sets cookie values within the current page's domain. (Or optionally a specifi…') |
|||
Line 5: | Line 5: | ||
__CR.cookie = function (name, value) { ... } | __CR.cookie = function (name, value) { ... } | ||
− | The name is the exact name of the query string variable to store. The value is a simple string or numeric value to store. Currently, no encoding of non-scalar structures is supported (e.g. objects, arrays) so you must encode and decode your content prior to passing into the <span class="code">__CR.cookie</span> call. | + | The '''name''' is the exact name of the query string variable to store. The '''value''' is a simple string or numeric value to store. Currently, no encoding of non-scalar structures (including null or false) is supported (e.g. objects, arrays) so you must encode and decode your content prior to passing into the <span class="code">__CR.cookie</span> call. Note as well that expressions which evaluate to '''false''' are not allowed as well. |
== Getting a cookie value == | == Getting a cookie value == | ||
Line 46: | Line 46: | ||
Note that the above should be customized for the type of elements targeted by [[jQuery]] as well as the action code names, depending on your installation. | Note that the above should be customized for the type of elements targeted by [[jQuery]] as well as the action code names, depending on your installation. | ||
+ | |||
+ | == Using a custom domain == | ||
+ | |||
+ | You can set the [[ConversionRuler JavaScript Global]] member <span class="code">domain</span> to use an alternate domain name (e.g. a shared top-level domain name, for example) prior to using these calls. | ||
+ | |||
+ | For example, if your site has the following domains: | ||
+ | |||
+ | * http://example.com/ | ||
+ | * http://www.example.com/ | ||
+ | * http://blog.example.com/ | ||
+ | * http://store.example.com/ | ||
+ | |||
+ | You would set the domain as follows: | ||
+ | |||
+ | <script> | ||
+ | window._crq = window._crq || []; | ||
+ | window._crq.push(function (cr) { | ||
+ | cr.domain = ".example.com"; | ||
+ | // Do cookie set/get calls | ||
+ | }); | ||
+ | </script> | ||
== See also == | == See also == |
Revision as of 18:52, 30 June 2016
__CR.query is a function which takes two parameters and gets or sets cookie values within the current page's domain. (Or optionally a specific domain.)
Contents
Setting a cookie value
__CR.cookie = function (name, value) { ... }
The name is the exact name of the query string variable to store. The value is a simple string or numeric value to store. Currently, no encoding of non-scalar structures (including null or false) is supported (e.g. objects, arrays) so you must encode and decode your content prior to passing into the __CR.cookie call. Note as well that expressions which evaluate to false are not allowed as well.
Getting a cookie value
__CR.cookie = function (name) { ... }
The name is the exact name of the query string variable to retrieve.
Deleting a cookie value
__CR.delete_cookie(name)
Deletes the cookie with name name if it exists.
Example usage - saving and recording an email address on two pages
On the form page:
<script> window._crq = window._crq || []; window._crq.push(function (cr) { cr.jquery(function ($) { var save_email = function () { cr.cookie("cr-email", $(this).val()); }; $('input[type=email],input.email').on("change", save_email).each(save_email); }); }); </script>
On the form thank you page:
<script> window._crq = window._crq || []; window._crq.push(function (cr) { cr.track('thank-you', null, cr.cookie('cr-email')); }); </script>
Note that the above should be customized for the type of elements targeted by jQuery as well as the action code names, depending on your installation.
Using a custom domain
You can set the ConversionRuler JavaScript Global member domain to use an alternate domain name (e.g. a shared top-level domain name, for example) prior to using these calls.
For example, if your site has the following domains:
You would set the domain as follows:
<script> window._crq = window._crq || []; window._crq.push(function (cr) {
cr.domain = ".example.com";
// Do cookie set/get calls }); </script>