Javascript Monitus Object Settings

Here are the different settings you can use to customize the monitus code on a store’s pages:

  • monitus.id int – required The store ID assigned by Monitus
  • monitus.health_check bool This stores participates in our daily stats for speed and health graphs. Mainly beta stores for now.
  • monitus.allow_frames bool Allow our code to run if it is called form within an iframe?
  • monitus.tools_off string Comma-delimited list of tool IDs to turn off (bypass)
  • monitus.callback function The callback used by our code at different point in its execution. See the documentation here
  • monitus.ga_mode number Load Classic GA and/or Universal Analytics? 0-none; 1-GA only; 2-UA only; 3-GA and UA
  • monitus.ga_url string – url The url to use for the GA javascript library.
  • monitus.ga_page string The page name to send to GA.

Upgrade to v4.0

To upgrade a store’s installation to the new v4 one liner:

  • Install the new code: Remove all traces of the old installation code: the static header file, and the monitus_init snippet. Replace with the new instructions, in the merchant’s .monitus.net account.
  • Clean up: Remove any usage of the old "pqTracker" variable, and make sure the merchant’s .monitus.net account is upgraded to use only one GA tracker.
  • Adjust custom code:
    • Use the new callback method instead of the legacy "monitus_ga_callback", or the even older still "monitus_ga_init", "monitus_customize_ga_tracker", and "monitus_final_callback"
    • Transform all MUI function calls into jMUI equivalent function calls. NOTE: consult the jMUI documentation for the updates parameter list and format! jMUI is jQuery-based, which changes the way you pass object or selectors to functions. If for some reason you must keep using the old MUI library, please make sure to load it before the new monitus one-liner; our code will then automatically load a translation library that transforms MUI calls to jMUI equivalents. Note however that this is not as efficient (extra file to load, extra code to run) so moving to the new jMUI call should be the end goal here.

GA callback function

For version 4, on all pages

<script type="text/javascript">
var monitus = monitus || {};
monitus.callback = function(pTrigger) {
    switch(pTrigger) {
        case "tracker_created":
            // The GA tracker has been created
            break;
        
        case "tracker_before_tracking":
            // Right before "_trackPageView" is called
            // appropriate for setting custom variables and content groups
            break;
        
        case "tracker_after_tracking":
            // After GA has tracked the current page view
            break;
        
        case "visitor_data_changed":
            // Called when the monitus.visitor data structure is updated with new values
            break;
        
        case "cart_setup":
            // Called when the cart recovery mechanism has been setup
            break;
    }
};
...
[regular monitus one-liner installaiton code]
</script>

For version 3.1 and earlier:

On non-checkout pages AND the confirmation page:

<script type="text/javascript">
  ...
  monitus_ga_callback = function(pStep, pTracker) {
   switch(pStep) {
    case "initialize":
      /*
      This step is for anything you want to do before the tracker is created; this should not be used to customize the tracker - use the "customize" case instead.
      ** pTracker is not used here.
      */
      break;
     
    case "customize":
      /*
      Customize the tracker object, before "_initData" is called on it.
      if you need to distinguish tracker objects (pqTracker, woTracker...) you can use the pTracker variable to compare, as in: if(pTracker == _MONITUS.pageTracker) { /*customize _MONITUS.pageTracker*/ }
      */
      break;
     
    case "finalize":
      /*
      In this step, the monitus pageview has been sent; note that on the confirmation page, the transaction has not been sent by this time.
      ** pTracker is not used here.
      */
      break;
     
    case "postprocess":
      /*
      This step happens at the very end of the GA coe - everything has been sent to GA.
      ** pTracker is not used here.
      */
      break;
   }
  }
  ...
  if(typeof(monitus_init) == "function") monitus_init(<store ID>, "new");
</script>


On the checkout wrapper page:

<script type="text/javascript">
  ...
  if(!document.URL.match(/sectionId=ysco.confirm/)) {
   monitus_ga_callback = function(pStep, pTracker) {
    switch(pStep) {
      case "initialize":
       /*
       This step is for anything you want to do before the tracker is created; this should not be used to customize the tracker - use the "customize" case instead.
       ** pTracker is not used here.
       */
       break;
      
      case "customize":
       /*
       Customize the tracker object, before "_initData" is called on it.
       if you need to distinguish tracker objects (pqTracker, woTracker...) you can use the pTracker variable to compare, as in: if(pTracker == _MONITUS.pageTracker) { /*customize _MONITUS.pageTracker*/ }
       */
       break;
      
      case "finalize":
       /*
       In this step, the monitus pageview has been sent; note that on the confirmation page, the transaction has not been sent by this time.
       ** pTracker is not used here.
       */
       break;
      
      case "postprocess":
       /*
       This step happens at the very end of the GA coe - everything has been sent to GA.
       ** pTracker is not used here.
       */
       break;
    }
   }
   ...
   if(typeof(monitus_init) == "function") monitus_init(<store ID>, "new");
  }
</script>

Google’s Missing Tools

GMT – Goolge’s Missing Tools

Here is a simple bookmarklet to complement all things Google:

GMT <- simply drag this link to your browser’s "Bookmarks" bar.

What does it do?

Google Analytics

  • Z-test: On any report, looking at the "Ecommerce" tab, use this button to compare any two rows; the tool will tell you if the conversion rate difference between the two is significant or not.

More to come, as we find new ways to improve "The Goog"…

Preserving Referrer through a javascript redirect

On the landing page that might use a javscript redirect, place this bit of code:

<script type="text/javascript">var monitus=monitus||{}; monitus.id=[[monitus store ID]];</script>
<script type="text/javascript" src="http://ldn..monitus.net/js/monitus.js"></script>
<script type="text/javascript">try{jMUI.yahoo.save_referrer_for_redirect();}catch(e){}</script>
[[...actual redirect script...]]
<script type="text/javascript">try{jMUI.yahoo.clear_referrer_for_redirect();}catch(e){}</script>

Then, on the redirected page, we need to grab the referrer back before we use it. In this example, we use the out-of-the-box GA code on the redirected page:

<script type="text/javascript" src="http://ldn..monitus.net/jmui.js"></script>
<script type="text/javascript">>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-1']);
var overridenRef = jMUI.utilities.cookie_value("_mrrf", null);
if(overridenRef) _gaq.push(['_setReferrerOverride', overridenRef]);
MUI.yahoo.clear_referrer_for_redirect();
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('http:' == document.location.protocol ? 'http://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Note: If the code is placed on a secure page (https), then the jMUI URL changes from "http://ldn..monitus.net/jmui.js" to "http://d35q1w5azactrh.cloudfront.net/jmui.js"