Difference between revisions of "CR.cookie"

From Market Ruler Help
Jump to: navigation, search
m
Line 60: Line 60:
 
You would set the domain as follows so that cookies would be shared between your domains:
 
You would set the domain as follows so that cookies would be shared between your domains:
  
<script>
+
<script>
window._crq = window._crq || [];
+
window._crq = window._crq || [];
window._crq.push(function (cr) {
+
window._crq.push(function (cr) {
                cr.domain = ".example.com";
+
    cr.domain = ".example.com";
// Do cookie set/get calls
+
    // Do cookie set/get calls
});
+
});
</script>
+
</script>
  
 
== See also ==
 
== See also ==

Revision as of 19:03, 30 June 2016

__CR.cookie 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 (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:

  • http://example.com/
  • http://www.example.com/
  • http://blog.example.com/
  • http://store.example.com/

You would set the domain as follows so that cookies would be shared between your domains:

<script>
window._crq = window._crq || [];
window._crq.push(function (cr) {
    cr.domain = ".example.com";
    // Do cookie set/get calls
});
</script>

See also