Difference between revisions of "Tracking Queue"

From Market Ruler Help
Jump to: navigation, search
m
m
 
(6 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
Note that this method should only be used when conversions do not reload the current page. The easiest way to determine this is if the page address stays the same (although this is not always the case.)
 
Note that this method should only be used when conversions do not reload the current page. The easiest way to determine this is if the page address stays the same (although this is not always the case.)
  
Data is communicated to ConversionRuler using an event queue which takes similar parameters to [[cr_track]].  
+
Data is communicated to ConversionRuler using an event queue which takes similar parameters to [[__CR.track]].  
  
 
To use the queue, you must initialize it to an empty array using the following code:
 
To use the queue, you must initialize it to an empty array using the following code:
  
 
  <script type="text/javascript">
 
  <script type="text/javascript">
  var _crq = window._crw || [];
+
  window._crq = window._crq || [];
 
  </script>
 
  </script>
  
Line 14: Line 14:
  
 
  <script type="text/javascript">
 
  <script type="text/javascript">
  _crq.push('clicked-button');
+
  window._crq.push('clicked-button');
 
  </script>
 
  </script>
  
Line 21: Line 21:
 
* '''The queue must be created within the global window scope'''
 
* '''The queue must be created within the global window scope'''
 
* '''The queue must be an array'''
 
* '''The queue must be an array'''
 +
* '''ConversionRuler will initialize _crq automatically - but depending on how your application is written, you should initialize it as well.'''
  
 
You can pass parameters to the queue as well, in which case you will pass an array to the queue, as follows:
 
You can pass parameters to the queue as well, in which case you will pass an array to the queue, as follows:
  
 
  <script type="text/javascript">
 
  <script type="text/javascript">
  _crq.push(['orders', '$29.99', '#51209035']);
+
  window._crq.push(['orders', '$29.99', '#51209035']);
 
  </script>
 
  </script>
  
The main difference is the passing of an array, the parameters match the ordering of parameters to [[cr_track]], e.g.
+
The main difference is the passing of an array, the parameters match the ordering of parameters to [[__CR.track]], e.g.
  
 
# Action Code
 
# Action Code
Line 39: Line 40:
 
# Amount 3
 
# Amount 3
 
# Text 3
 
# Text 3
 +
 +
You can also pass a function to the queue as well, which takes a single parameter which is the [[ConversionRuler JavaScript Global]] which contains functions and state for ConversionRuler itself:
 +
 +
<script>
 +
var _crq = window._crq || [];
 +
_crq.push(function (cr) {
 +
      // Note cr.track is the same as __CR.track here!
 +
      cr.track('contact', null, cr.cookie('cr-email'));
 +
  });
 +
</script>
 +
 +
'''This is extremely useful when you need to use ConversionRuler functionality but are not certain when ConversionRuler itself is loaded.''' Any functions passed into to the '''_crq''' queue will only be invoked:
 +
 +
* If ConversionRuler is installed
 +
* After ConversionRuler tracking scripts are loaded
  
 
To add an event to the queue deep within your JavaScript code, simply use '''window._crq''' in your code to access the global scope (assuming "window" is not replaced in the local scope), as follows:
 
To add an event to the queue deep within your JavaScript code, simply use '''window._crq''' in your code to access the global scope (assuming "window" is not replaced in the local scope), as follows:
Line 53: Line 69:
 
  </script>
 
  </script>
  
The Tracking Queue can be used as a drop-in replacement for [[cr_track]] in most cases.
+
The Tracking Queue can be used as a drop-in replacement for [[__CR.track]] in most cases.
  
 
[[Category:ConversionRuler]]
 
[[Category:ConversionRuler]]

Latest revision as of 22:37, 30 January 2021

ConversionRuler allows you to track events on your page which likely occur in a "Web Application" where the page URL is never reloaded, but content is loaded dynamically using AJAX and JavaScript. Many new applications, particularly for Mobile Devices, are written using this type of functionality, and so it makes sense to be able to easily communicate these to ConversionRuler with the minimum overhead required.

Note that this method should only be used when conversions do not reload the current page. The easiest way to determine this is if the page address stays the same (although this is not always the case.)

Data is communicated to ConversionRuler using an event queue which takes similar parameters to __CR.track.

To use the queue, you must initialize it to an empty array using the following code:

<script type="text/javascript">
window._crq = window._crq || [];
</script>

Simple enough. To send an event to ConversionRuler, you simply push an event on the end of the queue, as follows:

<script type="text/javascript">
window._crq.push('clicked-button');
</script>

Typically, this will be placed deep within your JavaScript application code. Note:

  • The queue must be created within the global window scope
  • The queue must be an array
  • ConversionRuler will initialize _crq automatically - but depending on how your application is written, you should initialize it as well.

You can pass parameters to the queue as well, in which case you will pass an array to the queue, as follows:

<script type="text/javascript">
window._crq.push(['orders', '$29.99', '#51209035']);
</script>

The main difference is the passing of an array, the parameters match the ordering of parameters to __CR.track, e.g.

  1. Action Code
  2. Amount 0
  3. Text 0
  4. Amount 1
  5. Text 1
  6. Amount 2
  7. Text 2
  8. Amount 3
  9. Text 3

You can also pass a function to the queue as well, which takes a single parameter which is the ConversionRuler JavaScript Global which contains functions and state for ConversionRuler itself:

<script>
var _crq = window._crq || [];
_crq.push(function (cr) {
      // Note cr.track is the same as __CR.track here!
      cr.track('contact', null, cr.cookie('cr-email'));
 });
</script>

This is extremely useful when you need to use ConversionRuler functionality but are not certain when ConversionRuler itself is loaded. Any functions passed into to the _crq queue will only be invoked:

  • If ConversionRuler is installed
  • After ConversionRuler tracking scripts are loaded

To add an event to the queue deep within your JavaScript code, simply use window._crq in your code to access the global scope (assuming "window" is not replaced in the local scope), as follows:

<script type="text/javascript">
function click_handler() {
   // Load AJAX code
   // Set options, etc.
   options.complete = function () {
      window._crq.push('show-signup-dialog');
   };
   $.ajax(options);
}
</script>

The Tracking Queue can be used as a drop-in replacement for __CR.track in most cases.