Custom Events

Custom Event

ButtonJS allows you to track events that are meaningful to your user journeys and success metrics. These may be things not explicitly commerce-focused, such as upvotes, adding to favorites, external clicks, or commenting on a post. All of these are perfect use cases for ButtonJS Custom Events.

Event Actions

You can easily send Custom Events to Button by using the action parameter. The value can be whatever you want but should be well structured and consistent for a particular action, where the value is indicative of the event itself. This will provide for cleaner reporting and better use of this data within PostTap.

The example below shows how to send Button a "like" action as a Custom Event:

// Click event
  elem.addEventListener('clickUpvoteButton', function(e) {
    // Fire ButtonJS Custom Event
    bttnio(
      'reportEvent',
      'onsite',
      {
        action: 'like' // 'like' is your custom event name
      },
    );
  
  });

Adding Contextual Information

You also have the ability to send contextual information along with a Custom Event. Do this by passing a free-form object to the extra property within the same object that contains the action event.

The information in the extra object can contain anything you want, and be as multi-nested as you wish. Below you'll see an example of the same upvote event as before, but this time with the extra object:

// Click event
  elem.addEventListener('clickUpvoteButton', function(e) {
    // Fire ButtonJS Custom Event
    bttnio(
      'reportEvent',
      'onsite',
      {
        action: 'like', // 'like' is your custom event name
        extra: {
          postId: 26, 
          pageType: 'search',
          pinnedPost: false
        },
      },
    );
  
  }, false);

Category Campaigning

Button's campaign targeting capabilities are best in class, giving you the power to "bucket" your Users based on their behavior on your website. To do this you can explicitly call the addUserToCampaignCategories action, along with a categories array. This will apply interest targeting capabilities to your subscribers.

Let's take a look at the example below:

// Fire ButtonJS Custom Event
  bttnio(
    'reportEvent',
    'onsite',
    {
      action: 'addUserToCampaignCategories',
      categories: [
        'Technology',
        'Mobile Phones',
        'Samsung',
        'Galaxy'
      ],
    },
  );

Multiple category values are interpreted as a hierarchy, assigning several category interest groupings to the User. In the above example, the User is now eligible for any engagement campaigns targeting an audience interested in any of the following groups:

  • Technology
  • Technology > Mobile Phones
  • Technology > Mobile Phones > Samsung
  • Technology > Mobile Phones > Samsung > Galaxy

You can cross-reference this when setting up your campaigns in the Button SMS Dashboard.