Difference between revisions of "CR.cookie"

From Market Ruler Help
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 36: Line 36:
 
  </script>
 
  </script>
  
**The above code will only be functional on a page which contains a [[ConversionRuler Tracking Snippet]].**
+
'''The above code will only be functional on a page which contains a [[ConversionRuler Tracking Snippet]].'''
  
 
On the form thank you page:
 
On the form thank you page:
Line 47: Line 47:
 
  </script>
 
  </script>
  
**The above code will only be functional on a page which contains a [[ConversionRuler Tracking Snippet]].**
+
'''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.
 
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.
Line 75: Line 75:
  
 
* [[:Category:ConversionRuler JavaScript Functions|JavaScript Functions]]
 
* [[:Category:ConversionRuler JavaScript Functions|JavaScript Functions]]
 +
* [[__CR.data]]
 
* [[__CR.query]]
 
* [[__CR.query]]
 
* [[__CR.jquery]]
 
* [[__CR.jquery]]

Latest revision as of 16:48, 14 November 2018

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

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.cookie('cr-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.

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