Scripting guidelines

To log goals and events  on page load, use the mtr.custom-variable to configure your logging variables.

var mtr_custom = mtr_custom || {};

To log goals and events  on user interaction such as when a user clicks a button (i.e. "Add to cart" or "Read this" or "Buy now") or when a user is scrolling, use one of these methods: 

mtr.log(url, pageTitle)
mtr.event(eventName)
mtr.goal(goalName)

These methods can only be used after the entire Triggerbee tracking script has loaded. 

Below is an example script that waits until the mtr-object containing the Triggerbee script is loaded. Insert it and call it on page load.

waitForMtr(function () {
  // variable exists, do what you want
  // for example call mtr.goal("Purchase complete!", "995");
});

function waitForMtr(callback) {
 var maxAttempts = 10;
 var counter = 0;
 checkIsInitialized();

 function checkIsInitialized() {
   if (typeof (window.mtr) !== "undefined") {
     callback();
   } else {
     if (counter < maxAttempts) {
       setTimeout(function () {
         counter++;
         checkIsInitialized();
       }, 250);
     }
   }
 }
}
	

Namespaces

Sometimes you might want to customize the logging using the mtr_custom object in a namespace of your own. Then the Triggerbee script can't read those customizations. 

To avoid this use the following trick that makes sure that the mtr_custom object is accessible in the global space accessed the Triggerbee mtr-logger:

window.mtr_custom = mtr_custom;
	
Did this answer your question? Thanks for the feedback! Please reach out to support@triggerbee.com if there's anything you'd like to add. There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us