CR.cookie

From Market Ruler Help
Revision as of 18:48, 30 June 2016 by Admin (talk | contribs) (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…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

__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.)

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 is supported (e.g. objects, arrays) so you must encode and decode your content prior to passing into the __CR.cookie call.

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.

See also