Files
fleet/website/api/controllers/deliver-gitops-workshop-request.js
T
johnjeremiahandEric cc2cb0a204 Add mostRecentCampaign to event records (#45750)
Following the pattern we have for Clay updating historical events with
the campaign name, this updates the historical event to include the
campaign name for website events.

After the contact is created/updated, we now include the campaign name
as a parameter for the historical event to update/populate the existing
field on the sfdc historical event object.




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

* **New Features**
* Historical events for signups, newsletter subscriptions, contact/quote
requests, whitepaper downloads, workshop requests, and page views now
include campaign association to improve marketing analytics.
* **Bug Fixes / Reliability**
* Webhooks now fall back to the most recent campaign when none is
provided.
* **Chores**
* Backend responses now expose a mostRecentCampaign field to support
campaign attribution.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/45750?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Eric <eashaw@sailsjs.com>
2026-05-22 22:38:29 -04:00

119 lines
4.2 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Deliver gitops request submission',
description: '',
inputs: {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
emailAddress: { type: 'string', isEmail: true, required: true },
location: { type: 'string', required: true },
numberOfHosts: { type: 'string', required: true },
managedPlatforms: { type: {}, required: true },
willingToHost: { type: 'string'},
},
exits: {
success: {
description: 'A gitops workshop request was submitted.'
},
invalidEmailDomain: {
description: 'This email address is on a denylist of domains and was not delivered.',
responseType: 'badRequest'
},
},
fn: async function ({firstName, lastName, location, emailAddress, numberOfHosts, managedPlatforms, willingToHost}) {
let emailDomain = emailAddress.split('@')[1];
if(_.includes(sails.config.custom.bannedEmailDomainsForWebsiteSubmissions, emailDomain.toLowerCase())){
throw 'invalidEmailDomain';
}
// Convert the managedPlatforms object into a string.
let platformFriendlyNamesByManagedPlatformValues = {
macos: 'macOS',
windows: 'Windows',
linux: 'Linux',
android: 'Android',
iosOrIpados: 'iOS/iPadOS',
chromeos: 'ChromeOS',
};
let managedPlatformsString = 'Selected platforms: ';
for(let selectedPlatform of _.keysIn(managedPlatforms)){
if(managedPlatforms[selectedPlatform] === true){
managedPlatformsString += `\n\t- ${platformFriendlyNamesByManagedPlatformValues[selectedPlatform]}`;
}
}
// Build a description with information from the form submission to add to the created/found contact record.
let descriptionForCrmUpdate =
`
Submitted the gitops workshop request form.
Submission information:
They are ${willingToHost ? '' : 'not '}interested in hosting a workshop at their company's office.
Location: ${location}
Email: ${emailAddress}
Number of hosts: ${numberOfHosts}
${managedPlatformsString}
`;
let attributionCookieOrUndefined = this.req.cookies.marketingAttribution;
await sails.helpers.flow.build(async ()=>{
let recordDetails = await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
contactSource: 'Website - GitOps',
description: descriptionForCrmUpdate,
marketingAttributionCookie: attributionCookieOrUndefined
}).intercept((err)=>{
return new Error(`Could not create/update a contact or account. Full error: ${require('util').inspect(err)}`);
});
// Add contact to campaign.
await sails.helpers.salesforce.createCampaignMember.with({
salesforceContactId: recordDetails.salesforceContactId,
salesforceCampaignId: '701UG00000bLCLpYAO',// 2026_01-FE-GitOps_Workshop_Interest Campaign
});
if(!recordDetails.salesforceAccountId) {
throw new Error(`Could not create historical event. The contact record (ID: ${recordDetails.salesforceContactId}) returned by the updateOrCreateContactAndAccount helper is missing a parent account record.`);
}
// Create the new historical event record.
await sails.helpers.salesforce.createHistoricalEvent.with({
salesforceAccountId: recordDetails.salesforceAccountId,
salesforceContactId: recordDetails.salesforceContactId,
eventType: 'Intent signal',
intentSignal: 'Submitted the "GitOps workshop request" form',
eventContent: descriptionForCrmUpdate,
relatedCampaign: recordDetails.mostRecentCampaign,
}).intercept((err)=>{
return new Error(`Could not create an historical event. Full error: ${require('util').inspect(err)}`);
});
}).tolerate((err)=>{
sails.log.warn(`When a user (${firstName} ${lastName}, email: ${emailAddress}) submitted the gitops workshop request form, an error occured when updating CRM records for this user.\n Submission information: ${descriptionForCrmUpdate.split('Submission information:')[1]}\n Full error: ${require('util').inspect(err)}`);
});
// All done.
return;
}
};