Difference between revisions of "ConversionRuler JavaScript Global"

From Market Ruler Help
Jump to: navigation, search
(Created page with 'ConversionRuler, starting in 2016, stores most state and functional information within a single JavaScript global variable available in the global scope (or '''window''' scop…')
 
(adding instrument)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
ConversionRuler, starting in 2016, stores most state and functional information within a single [[JavaScript]] global variable available in the global scope (or '''window''' scope):
 
ConversionRuler, starting in 2016, stores most state and functional information within a single [[JavaScript]] global variable available in the global scope (or '''window''' scope):
  
## __CR
+
== window.__CR ==
  
 
The JavaScript global '''__CR''' has the following fields and properties which are publicly accessible. Note the presence of the global in the '''window''' scope generally asserts that ConversionRuler tracking has been loaded and performed.
 
The JavaScript global '''__CR''' has the following fields and properties which are publicly accessible. Note the presence of the global in the '''window''' scope generally asserts that ConversionRuler tracking has been loaded and performed.
Line 11: Line 11:
 
* <span class="code">[[__CR.query]]</span> - ''function'' - Retrieve a value from the current page URL's query string
 
* <span class="code">[[__CR.query]]</span> - ''function'' - Retrieve a value from the current page URL's query string
 
* <span class="code">[[__CR.jquery]]</span> - ''function'' - Load the [[jQuery]] library if it is not present in the global scope, and invoke the passed in function with the jQuery JavaScript global
 
* <span class="code">[[__CR.jquery]]</span> - ''function'' - Load the [[jQuery]] library if it is not present in the global scope, and invoke the passed in function with the jQuery JavaScript global
 +
* <span class="code">[[__CR.instrument]]</span> - ''function'' - Capture values from forms and store them for later
 
* <span class="code">[[__CR.cookie]]</span> - ''function'' - Retrieve a value from the current site's cookies
 
* <span class="code">[[__CR.cookie]]</span> - ''function'' - Retrieve a value from the current site's cookies
 
* <span class="code">__CR.site</span> - ''string'' - Site ID most recently tracked by ConversionRuler
 
* <span class="code">__CR.site</span> - ''string'' - Site ID most recently tracked by ConversionRuler
Line 36: Line 37:
 
  });
 
  });
 
  </script>
 
  </script>
 +
 +
== window._crq ==
 +
 +
The <span class="code">_crq</span> global is used to submit tracking commands to ConversionRuler in a way which supports asynchronous loading of ConversionRuler. The tracking queue is recorded upon the first load of ConversionRuler, and then is checked every 100 milliseconds for modification and recording. Read more about the [[Tracking Queue]].
  
 
== See also ==
 
== See also ==
Line 42: Line 47:
  
 
[[Category:ConversionRuler]]
 
[[Category:ConversionRuler]]
 +
[[Category:ConversionRuler JavaScript Functions]]

Latest revision as of 01:53, 11 May 2020

ConversionRuler, starting in 2016, stores most state and functional information within a single JavaScript global variable available in the global scope (or window scope):

window.__CR

The JavaScript global __CR has the following fields and properties which are publicly accessible. Note the presence of the global in the window scope generally asserts that ConversionRuler tracking has been loaded and performed.

  • __CR.track - function - Track an action on this page
  • __CR.track_id - function - Track an element by ID on the page
  • __CR.link - function - Track links which direct to another page which may not have tracking ability
  • __CR.submit - function - Track forms which submit to another page which may not have tracking ability
  • __CR.query - function - Retrieve a value from the current page URL's query string
  • __CR.jquery - function - Load the jQuery library if it is not present in the global scope, and invoke the passed in function with the jQuery JavaScript global
  • __CR.instrument - function - Capture values from forms and store them for later
  • __CR.cookie - function - Retrieve a value from the current site's cookies
  • __CR.site - string - Site ID most recently tracked by ConversionRuler
  • __CR.url - string - URL of the current page
  • __CR.frame - boolean - If the current page where ConversionRuler was loaded is an iframe or is within a HTML frame
  • __CR.user - string - Unique ID used by ConversionRuler to identify the current site visitor.

Access to any variables not named or listed above is not supported.

This global variable is passed as the first parameter to any function which is registered using the Tracking Queue. That is, the following snippets of code are equivalent:

<script>
window._crq = window._crq || [];
window._crq.push(function (cr) {
    cr.track('action');
});
</script>

is equivalent to:

<script>
window._crq = window._crq || [];
window._crq.push(function () {
    __CR.track('action');
});
</script>

window._crq

The _crq global is used to submit tracking commands to ConversionRuler in a way which supports asynchronous loading of ConversionRuler. The tracking queue is recorded upon the first load of ConversionRuler, and then is checked every 100 milliseconds for modification and recording. Read more about the Tracking Queue.

See also