Trigger Intercom Chat Messages to Churn Risk Customers (using Segment and SQL database data)

This recipe combines usage data from your analytics tools and your database, and estimates whether they'll be likely to churn or not. It then triggers an automated Intercom chat and email message to take action.

Install the SQL Database Importer to Pass Custom Data to Hull

The SQL Database Importer hooks into your PostgreSQL or Redshift database, lets you define a query that will be run on a regular schedule and import the results into Hull.

You can choose to fetch only updated users or the full data set when you build your query. We provide a way to put in a placeholder that will be replaced with the timestamp of the previous query.

Once Users are imported in Hull, only those who have changed will actually be re-sent to other connectors

The SQL imported does not write in your database - we recommend you provide read-only credentials to increase security.

To connect the SQL Database connector, go to Ships. You’ll need to select your Database type (Postgres or MySQL), enter it’s location, username and password, enter a Connection String and write a SQL query to extract the right data into Hull.

By default, this will run every 3 hours.

Install Segment to Pass Analytics Data to Hull

Segment is a data pipe for sending customer data from one tool to another set of tools (including Hull).

In this case, the source needs to be analytics events with identified individuals on your website. To capture this data, Segment needs to be installed.

To set this up, you need to install Segment in the page on your website (or mobile and server side options). To set this up for you, review Segment’s documentation here.. This data (including analytics events and page views) can be passed to other tools and services - including Hull.

To setup Hull as a destination, go to the Sources page in your Segment Workspace. Click on the source you have setup (e.g. Javascript, if you’ve installed Segment’s analytics.js script) - you’ll land on an overview page.

Choose “Integrations” from the top navigation. You’ll see a catalog of different tools you can send your analytics data to from Segment. Search for and click Hull.

Under “Settings” on the left hand side, you’ll need to paste your Hull API key. You can find your Hull API key within your Hull account.

Login to Hull, go to the Ships tab, and choose “Install Ship”. On the settings page, copy the Hull API key from the right hand side and paste it into the Hull integrations page on Segment. You can then add Hull as a destination from Segment.

Create a Segment of Churn Risk Users

Of the key events being tracked with Segment and your database in your app which are positive, and are negative:

  • Installed
  • User invited
  • Report exported
  • Save button clicked

  • Error message received

  • Uninstalled

The combinations of the churn risk customers will be specific to your business. Low numbers or "intensity" of positive actions, and/or high numbers of negative actions contribute to a churn risk.

There are two ways to calculate this:

  1. Create a segment: If any "group of negative events" occurred > X times, or any "group of positive events" occurred < Y, all within the trial period. The easiest way to a filter group in Hull's segment builder and select "any". Inside this filter group, list all your actions.

  2. Calculate a score: Create a usage score by adding values for positive actions and taking away values for negative actions. This score can be synced as an attribute on a user's profile to other services, and calculated in a segment. This is possible with the Hull Processor by writing simple javascript code to create new properties from existing data.

Here's an example for usage scoring used by a Hull customer.

let score = 0;

const {
  account_isbeta = false,
  account_istrialexpired = false,
  embedcodeinstalled = false,
  account_triallengthdays = 0,
  totalcustomproperties = 0,
  account_domains = "",
  totalflows = 0,
  isinviteduser = false
} = user.traits;

if (account_isbeta) score += 3.6164;
if (account_istrialexpired) score -= 0.9303;
if (embedcodeinstalled) score += (4.2636 * 2);
if (account_triallengthdays > 14) score += 2.8537;


if (!isInSegment('Recent Users')) score -= 0.0801;


if (totalcustomproperties > 0) {
  let base = 3.7421;
  if (totalcustomproperties >= 5) {
    score += (base * 2);
  } else {
    score += base;


const account_domains_array = (account_domains||"").split(',')
if (account_domains_array.length === 1) score -= -0.5517;

if (totalflows > 0) {
  let base = 3.782;
  if (totalflows >= 5) {
    score += (base * 3);
  } else if (totalflows >= 3) {
    score += (base * 2);
  } else {
    score += base;


//compute total event count;
const eventCount = _.reduce(events, (c, e) => {
  const { event } = e;
  if (c[event]) {
  } else {
    c[event] = { value: 1, operation: 'inc' } ;
  return c;
}, {});
traits(eventCount, {source: 'event_counts'});


//off by one loop, but will reconcile.
const { event_counts } = user;

if (event_counts){
  score = _.reduce({
    "activated integration": 4,
    "created a style": 6,
    "invited a user": 3,
    "requested csv export": 5,
    "viewed subscription": 2,
    "published a set of hotspots": 4,
    "published a modal": 4
  }, (score, multiplier, name) => (score + (multiplier*(event_counts[name]||0)))
  , score);


traits({usage_score: score});

With your segment or usage score, you can now share that with your other tools.

Install Intercom

Intercom lets you publish website chat messages, emails and push notifications. The logic of what messages get trigger and to who is controlled inside of Intercom.

Hull helps you manage the segments who see each message, as well as create a richer profile to personalise your messages with data from other tools.

To install the Intercom ship, go to “Ships” and click “Add Ship”. Search and find Intercom. You’ll be asked to login with your Intercom credentials. Your data will start flowing to and from Intercom.

Make sure to carefully select which contacts you sync to Intercom, so you don’t incur a huge bill for the number of contacts.

Sync Contact Fields and Segments to Intercom

On the Intercom Ship page, choose settings. Here, you’ll see a field “Filtered Segments”. This has a dropdown and autocomplete field to add segments you want to sync with Intercom, like Churn Risk

Below, you can see the list of user attributes to push to Intercom. Select the new fields you want inside of Intercom like Usage Score

You can also fetch custom attributes (Hull will pull in all the default attributes) from Intercom that you’ve setup in Intercom.

When you’re done, click “Save” to start syncing your segments and profiles.

Setup customised web chat in Intercom

Inside the Intercom app, create a new Auto Message. Under "Write Your Message" you'll see the text editor. As you hover over on the right hand side, you'll see the list of user attributes. If you scroll through these, you should start to see other attributes. Select the attributes you want (like your usage score).

Under 'Choose Your Audience' you can select the audience from a Hull Segment, or a custom attribute (like a usage score).



How can you implement this at your company?

Thanks , We'll be in touch!

Get in touch to organise your customized cookbook of Sales and Marketing automation recipes

Liked this recipe? Share it!