Emit a new eventUpdated 30/04/2019


This snippet emits a new event when something changes in Hull. This allows you to emit milestone events to external services.


if (changes.user) {
  const { mrr } = changes.user;
  // mrr == [ PREVIOUS_VALUE, NEW_VALUE ];
  if (mrr) {
    if (!mrr[0]) {
      hull.track("Customer Subscribed", { mrr: mrr[1] })
    } else if (mrr[1] > mrr[0]) {
      hull.track("Customer Upgraded", {
        previous_mrr: mrr[0]
        mrr: mrr[1],
        difference: mrr[1] - mrr[0]
      })
    } else if (mrr[1] < mrr[0]) {
      hull.track("Customer Downgraded") {
        previous_mrr: mrr[0],
        mrr: mrr[1],
        difference: mrr[1] - mrr[0]
      }
    }
  }
}