Created
January 7, 2019 19:59
-
-
Save edfryed/0b542ab8272c92b17cf228fe35afd0c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write Datanyze Alerts into Account Attributes | |
// and as a (fake) User Event => can only trigger enrichment & prospecting with User Segments | |
// If it looks like it has a .com and a subdomain | |
// Or allow anything with a two-part domain (e.g. outshine.ca) | |
if ((_.endsWith(body.data.domain, ".com")) && (_.size(_.split(body.data.domain, ".", 3)) > 2)) { | |
// Strip off the sub-domain | |
var domain_cleansed = | |
_.trimStart( | |
_.trim( | |
body.data.domain, | |
_.head( | |
_.split( | |
body.data.domain, ".", 3 | |
) | |
) | |
), "." | |
); | |
} else if (_.size(_.split(body.data.domain, ".", 3)) == 2) { | |
var domain_cleansed = body.data.domain; | |
} | |
console.log(domain_cleansed) | |
// Only run if the domain looks good | |
if (_.isEmpty(domain_cleansed) == false) { | |
// To write to a User, need an email or anonymous_id | |
// Generate an anonymous_id from concatenating "datanyze_alerts;", event, technology, timestamp, and unique webhook ID | |
// Force the user creation. Break the rules... | |
const datanyze_alert_fake_user_id = _.concat("datanyze_alerts:"+body.data.event+body.data.technology+body.data.timestamp+body.id); | |
console.log(datanyze_alert_fake_user_id) | |
// Write Technology Added/Dropped Events into fake User profiles | |
// Track technology added | |
if(body.data.event == "add") { | |
hull.user({ anonymous_id: datanyze_alert_fake_user_id }).track("Technology added", { | |
Technology: body.data.technology, | |
Time: body.data.timestamp | |
}) | |
} | |
// Track technology dropped | |
if(body.data.event == "drop") { | |
hull.user({ anonymous_id: datanyze_alert_fake_user_id }).track("Technology dropped", { | |
Technology: body.data.technology, | |
Time: body.data.timestamp | |
}) | |
} | |
// Write domain_cleansed to user.domain | |
// Write a fake email (just to trigger enrichment connectors later) | |
hull.user({ anonymous_id: datanyze_alert_fake_user_id }).traits({ domain: domain_cleansed, email: "contact@"+domain_cleansed }) | |
// Write Technology Added/Dropped dates as Account Attributes | |
// Write Datanyze Alert set | |
hull.account({ domain: domain_cleansed }).traits({ datanyze_alert_set: true }) | |
// Added Clearbit Reveal | |
if(body.data.event == "add" && body.data.technology == "Clearbit Reveal") { | |
hull.account({ domain: domain_cleansed }).traits({ added_clearbit_reveal_date: body.data.timestamp }) | |
} | |
// Dropped Clearbit Reveal | |
if(body.data.event == "drop" && body.data.technology == "Clearbit Reveal") { | |
hull.account({ domain: domain_cleansed }).traits({ dropped_clearbit_reveal_date: body.data.timestamp }) | |
} | |
// Added Salesforce | |
if(body.data.event == "add" && body.data.technology == "Salesforce") { | |
hull.account({ domain: domain_cleansed }).traits({ added_salesforce_date: body.data.timestamp }) | |
} | |
// Dropped Salesforce | |
if(body.data.event == "drop" && body.data.technology == "Salesforce") { | |
hull.account({ domain: domain_cleansed }).traits({ dropped_salesforce_date: body.data.timestamp }) | |
} | |
// Added Segment | |
if(body.data.event == "add" && body.data.technology == "Segment") { | |
hull.account({ domain: domain_cleansed }).traits({ added_segment_date: body.data.timestamp }) | |
} | |
// Dropped Segment | |
if(body.data.event == "drop" && body.data.technology == "Segment") { | |
hull.account({ domain: domain_cleansed }).traits({ dropped_segment_date: body.data.timestamp }) | |
} | |
// Added HubSpot | |
if(body.data.event == "add" && body.data.technology == "HubSpot") { | |
hull.account({ domain: domain_cleansed }).traits({ added_hubspot_date: body.data.timestamp }) | |
} | |
// Dropped HubSpot | |
if(body.data.event == "drop" && body.data.technology == "HubSpot") { | |
hull.account({ domain: domain_cleansed }).traits({ dropped_hubspot_date: body.data.timestamp }) | |
} | |
// Added Intercom | |
if(body.data.event == "add" && body.data.technology == "Intercom") { | |
hull.account({ domain: domain_cleansed }).traits({ added_intercom_date: body.data.timestamp }) | |
} | |
// Dropped Intercom | |
if(body.data.event == "drop" && body.data.technology == "Intercom") { | |
hull.account({ domain: domain_cleansed }).traits({ dropped_intercom_date: body.data.timestamp }) | |
} | |
// Added Customer.io | |
if(body.data.event == "add" && body.data.technology == "Customer.IO") { | |
hull.account({ domain: domain_cleansed }).traits({ added_customerio_date: body.data.timestamp }) | |
} | |
// Dropped Customer.io | |
if(body.data.event == "drop" && body.data.technology == "Customer.IO") { | |
hull.account({ domain: domain_cleansed }).traits({ dropped_customerio_date: body.data.timestamp }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment