CR.data

From Market Ruler Help
Revision as of 16:49, 14 November 2018 by Admin (talk | contribs)
Jump to: navigation, search

__CR.data is a function which takes two parameters and gets or sets values within the current page's domain. Data is available on any page which shares cookies with the current domain, and data values are generally stored in a cookie called __cr_state and encoded using JSON.

Getting and setting data is intended for small bits of data, generally storing form values which are limited in length and other state values related to the current tracking of the visitor. Data values are stored as Name-Value Pairs.

Setting a data value

__CR.data = function (name, value) { ... }

The name is the exact name of the variable to store. The value is a simple string, object, or numeric value to store. Values which are arbitrarily large (such as objects or deep structures) should be avoided as they can cause issues with servers which reject cookies which grow beyond a certain size limit.

Getting a data value

 __CR.data = function (name) { ... }

The name is the exact name of the variable to retrieve. If not found, null is returned.

Deleting a data value

__CR.data(name, null)

Deletes the data 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.data("email", $(this).val());
		};
		$('input[type=email],input.email').on("change", save_email).each(save_email);
	});
});
</script>

The above code will only be functional on a page which contains a ConversionRuler Tracking Snippet.

On the form thank you page:

<script>
window._crq = window._crq || [];
window._crq.push(function (cr) {
	cr.track('thank-you', null, cr.data('email'));
});
</script>

The above code will only be functional on a page which contains a ConversionRuler Tracking Snippet.

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