Logging Goals and Events with JavaScript

hNote: If you haven't read An intro to Goals in Triggerbee, we suggest you do that first. This article is written for developers, and only covers JavaScript methods of logging Goals.

As a developer, you have complete freedom when it comes to keeping track of important events contributing towards your online success.

Page views: mtr.log()

This is the default event, used for logging page views. The method accepts a URL and the TITLE of the page.

Goals: mtr.goal()

These logs goals in Triggerbee. A goal is an important event that can be used to trigger automation events. Achieved goals are added to the contact, and can also be added to the subscriber in the email software and CRM. The method accepts the name of the goal and the revenue.

Events: mtr.event()

These events should be used to log small interaction events, like clicking on an image, swiping, adding products to cart etc. The method accepts an optional argument declaring the event type also, such as "scroll" and "shopping cart". NOTE: Events does not support filtering or segmentations (for the time being). They are only useful for inspecting sessions in the visits feed.


mtr.log("/services", "Services");

Logging a simple event

Events appear below the URL of the previously logged pageview.

mtr.event( "Filled out form field");
mtr.event("Clicked on button");
mtr.event("50%", "scroll");

Logging a goal

mtr.goal("Posted a form"); 
mtr.goal("Checked out cart", 310); // 310 is the revenue

Logging a goal on page load with some logic

if (window.addEventListener) {
  window.addEventListener('load', (event) => {
          && (getCookie("Is Premium member")==true))
         mtr.goal('Successful payment from premium member'); 

Note: To log goals and events on page load we recommend using the mtr.custom variable to configure the logging variables. To log goals and events on user interaction, such as clicking on buttons, scrolling, use the mtr.log(), mtr.event() and mtr.goal() methods. These methods are available after the tracking code is registered.  Read our scripting guidelines.

Did this answer your question? Thanks for the feedback! Please reach out to [email protected] 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