Files
fleet/website/api/helpers/salesforce/create-historical-event.js
T
Eric 85692f8238 Website: set historical event source (#50546)
Changes:
- Updated the website's createHistoricalEvent helper to accept an
eventSource input that is used to set the historical event source on
created records.
- Updated places where we create historical events to set a historical
event source
- Updated the accepted contact sources values in the receive-from-clay
webhook
- Updated the deliver-gitops-workshop-request action to log a warning
when a campaign member record cannot be created

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Improvements**
- Improved activity tracking for newsletter subscriptions, signups,
contact forms, workshop requests, webinars, gated content, and page
views.
- Added clearer source details to records for more accurate attribution.
- Expanded support for website, webinar, event, LinkedIn, prospecting,
and GitHub activity sources.
- **Bug Fixes**
- Workshop requests now continue successfully if campaign updates
encounter an error.
- Corrected warning messages and preserved relevant submission details
for troubleshooting.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-04 18:26:14 -05:00

196 lines
6.5 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Create Historical event',
description: 'Create a historical event related to a particular contact and account in Salesforce.',
inputs: {
// Required values on new historical event records.
salesforceAccountId: {
type: 'string',
required: true,
extendedDescription: 'This ID of the account associated with this historical event'
},
salesforceContactId: {
type: 'string',
required: true,
extendedDescription: 'This ID of the contact associated with this historical event'
},
eventType: {
type: 'string',
required: true,
isIn: [
'Intent signal',
'Website page view',
],
},
// For "Website page view" type historical events:
fleetWebsitePageUrl: {
type: 'string',
description: 'The url of the page this user viewed.',
extendedDescription: 'This input is required when the event type is "Website page view".'
},
websiteVisitReason: {
type: 'string',
description: ''
},
// For "Intent signal" type historical events:
intentSignal: {
type: 'string',
isIn: [
'Followed the Fleet LinkedIn company page',
'LinkedIn comment',
'LinkedIn share',
'LinkedIn reaction',
'Fleet channel member in MacAdmins Slack',
'Fleet channel member in osquery Slack',
'Implemented a trial key',
'Signed up for Fleet event',
'Registered for a conference',
'Engaged with Fleetie at event',
'Attended a Fleet happy hour',
'Stared the fleetdm/fleet repo on GitHub',
'Forked the fleetdm/fleet repo on GitHub',
'Contributed to the fleetdm/fleet repo on GitHub',
'Subscribed to the Fleet newsletter',
'Attended a Fleet training course',
'Submitted the "Send a message" form',
'Scheduled a "Talk to us" meeting',
'Scheduled a "Let\'s get you set up" meeting',
'Submitted the "GitOps workshop request" form',
'Signed up for a fleetdm.com account',
'Requested whitepaper download',
'Created a quote for a self-service Fleet Premium license',
'Requested webinar recording',
'Requested Fleet swag',
]
},
eventContent: {
type: 'string',
},
eventContentUrl: {
type: 'string',
},
linkedinUrl: {
type: 'string',
},
relatedCampaign: {
type: 'string',
},
eventSource: {
type: 'string',
isIn: [
'Attended a call with Fleet',
'Event',
'Event - 2026-07 PSU MacAdmins',
'Event - Webinar',
'Event - Workshop - GitOps',
'GitHub - Contributed to fleetdm/fleet',
'GitHub - Forked fleetdm/fleet',
'GitHub - Stared fleetdm/fleet',
'LinkedIn - Comment',
'LinkedIn - Liked the LinkedIn company page',
'LinkedIn - Reaction',
'LinkedIn - Share',
'Prospecting - AE',
'Prospecting - Meeting service',
'Prospecting - Specialist',
'Website - Chat',
'Website - Contact forms',
'Website - Contact forms - Demo',
'Website - Contact forms - Demo - ICP',
'Website - Gated document',
'Website - Gated video',
'Website - Newsletter',
'Website - Sign up',
'Website - Swag request',
'Website - Workshop request'
],
}
},
exits: {
success: {
outputType: {
salesforceHistoricalEventId: 'string',
},
},
},
fn: async function ({ salesforceAccountId, salesforceContactId, eventType, linkedinUrl, intentSignal, eventContent, eventContentUrl, fleetWebsitePageUrl, websiteVisitReason, relatedCampaign, eventSource}) {
// Return undefined if we're not running in a production environment.
if(sails.config.environment !== 'production') {
sails.log.verbose('Skipping Salesforce integration...');
return {
salesforceHistoricalEventId: undefined
};
}
require('assert')(sails.config.custom.salesforceIntegrationPasskey);
require('assert')(sails.config.custom.salesforceIntegrationUsername);
require('assert')(sails.config.custom.RX_PROTOCOL_AND_COMMON_SUBDOMAINS);
// Normalize the provided linkedin url.
if(linkedinUrl){
linkedinUrl = linkedinUrl.replace(sails.config.custom.RX_PROTOCOL_AND_COMMON_SUBDOMAINS, '');
}
// Check for required values depending on the eventType value.
if(eventType === 'Intent signal') {
if(!intentSignal) {
throw new Error(`A intentSignal value is required when creating "Intent signal" type historical events`);
}
} else if(eventType === 'Website page view') {
if(!fleetWebsitePageUrl){
throw new Error(`A fleetWebsitePageUrl value is required when creating "Website page view" type historical events`);
}
}
// Use sails.helpers.flow.build to login to salesforce and create the new histrocial event record.
let newHistoricalRecord = await sails.helpers.flow.build(async ()=>{
// login to Salesforce
let jsforce = require('jsforce');
let salesforceConnection = new jsforce.Connection({
loginUrl : 'https://fleetdm.my.salesforce.com'
});
await salesforceConnection.login(sails.config.custom.salesforceIntegrationUsername, sails.config.custom.salesforceIntegrationPasskey);
return await salesforceConnection.sobject('fleet_website_page_views__c')
.create({
Contact__c: salesforceContactId,// eslint-disable-line camelcase
Account__c: salesforceAccountId,// eslint-disable-line camelcase
Event_type__c: eventType,// eslint-disable-line camelcase
Intent_signal__c: intentSignal,// eslint-disable-line camelcase
Content__c: eventContent,// eslint-disable-line camelcase
Content_url__c: eventContentUrl,// eslint-disable-line camelcase
Interactor_profile_url__c: linkedinUrl,// eslint-disable-line camelcase
Page_URL__c: fleetWebsitePageUrl,// eslint-disable-line camelcase
Website_visit_reason__c: websiteVisitReason,// eslint-disable-line camelcase
Related_campaign__c: relatedCampaign,// eslint-disable-line camelcase
Historical_event_source__c: eventSource// eslint-disable-line camelcase
});
}).intercept((err)=>{
return new Error(`An error occured when creating a new Historical event record in Salesforce. full error ${require('util').inspect(err, {depth: null})}`);
});
return newHistoricalRecord.id;
}
};