Consolidate Subscription Status valuesUpdated 21/05/2019


Aggregates the subscription status of several marketing services to compute a unified "unsubscribed" status


// const changes = {
//   mailchimp: {
//     subscribed: [null, true]
//   },
//   intercom: {
//     unsubscribed_from_emails: [true, false]
//   },
//   hubspot: {
//     hs_email_optout: [false, true]
//   }
// }

// const user = {
//   accepts_marketing: undefined,
//   mailchimp: {
//     subscribed: true
//   },
//   intercom: {
//     unsubscribed_from_emails: false
//   },
//   hubspot: {
//     hs_email_optout: false
//   }
// }

const { intercom, mailchimp, hubspot } = user;

const merged_value = mailchimp.subscribed || !intercom.unsubscribed_from_emails || !hubspot.hs_email_optout;
const changed_value = undefined;

if (changes.mailchimp && changes.mailchimp.subscribed) {
  // use mailchimp value if mailchimp just changed
  changed_value = changes.mailchimp.subscribed[1];
} else if (changes.intercom && changes.intercom.unsubscribed_from_emails) {
  // use intercom value value if intercom value just changed
  changed_value = !changes.intercom.unsubscribed_from_emails[1];
} else if (changes.hubspot && changes.hubspot.hs_email_optout) {
  // use hubspot value value if hubspot value just changed
  changed_value = !changes.hubspot.hs_email_optout[1];
}


accepts_marketing = changed_value !== undefined ? changed_value : merged_value;
hull.traits({ accepts_marketing });
//Then send this value to your tools and use it to exclude people.