mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
Website: Set psychologicalStageChangeReason and intentSingals on contacts created from newsletter submissions (#23544)
Closes: https://github.com/fleetdm/confidential/issues/8690 Closes: https://github.com/fleetdm/confidential/issues/8691 Changes: - Updated the update-or-create-contact-and-account to set intentSignals on contacts - Updated create-or-update-one-newsletter-subscription to set psychologicalStageChangeReason and intentSignal on contacts.
This commit is contained in:
parent
dfe308f98d
commit
6065fa5d77
2 changed files with 39 additions and 5 deletions
|
|
@ -41,20 +41,28 @@ module.exports = {
|
|||
.tolerate('E_UNIQUE');
|
||||
|
||||
await NewsletterSubscription.updateOne({emailAddress: emailAddress}).set({isSubscribedToReleases: true});
|
||||
|
||||
let psychologicalStageChangeReason = 'Website - Newsletter';
|
||||
if(this.req.session.adAttributionString && this.req.session.visitedSiteFromAdAt) {
|
||||
let sevenDaysAgoAt = Date.now() - (1000 * 60 * 60 * 24 * 7);
|
||||
// If this user visited the website from an ad, set the psychologicalStageChangeReason to be the adCampaignId stored in their session.
|
||||
if(this.req.session.visitedSiteFromAdAt > sevenDaysAgoAt) {
|
||||
psychologicalStageChangeReason = this.req.session.adAttributionString;
|
||||
}
|
||||
}
|
||||
|
||||
sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
|
||||
emailAddress: emailAddress,
|
||||
contactSource: 'Website - Newsletter',
|
||||
description: `Subscribed to the Fleet newsletter`,
|
||||
psychologicalStage: '3 - Intrigued',
|
||||
psychologicalStageChangeReason: 'Website - Newsletter',
|
||||
psychologicalStageChangeReason,
|
||||
intentSignal: 'Subscribed to the Fleet newsletter',
|
||||
}).exec((err)=>{// Use .exec() to run the salesforce helpers in the background.
|
||||
if(err) {
|
||||
sails.log.warn(`Background task failed: When a user signed up for a newsletter, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err);
|
||||
}
|
||||
return;
|
||||
});
|
||||
});//_∏_
|
||||
|
||||
// All done.
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@ module.exports = {
|
|||
},
|
||||
getStartedResponses: {
|
||||
type: 'string',
|
||||
},
|
||||
intentSignal: {
|
||||
type: 'string',
|
||||
isIn: [
|
||||
'Subscribed to the Fleet newsletter',
|
||||
// 'Signed up for a fleetdm.com account',//
|
||||
// 'Submitted the "Talk to us" form',
|
||||
// 'Submitted the "Send a message" form',
|
||||
],
|
||||
}
|
||||
|
||||
},
|
||||
|
|
@ -60,8 +69,7 @@ module.exports = {
|
|||
|
||||
},
|
||||
|
||||
|
||||
fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, psychologicalStageChangeReason, contactSource, description, getStartedResponses}) {
|
||||
fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, psychologicalStageChangeReason, contactSource, description, getStartedResponses, intentSignal}) {
|
||||
// Return undefined if we're not running in a production environment.
|
||||
if(sails.config.environment !== 'production') {
|
||||
sails.log.verbose('Skipping Salesforce integration...');
|
||||
|
|
@ -114,6 +122,9 @@ module.exports = {
|
|||
if(psychologicalStageChangeReason) {
|
||||
valuesToSet.Psystage_change_reason__c = psychologicalStageChangeReason;// eslint-disable-line camelcase
|
||||
}
|
||||
if(intentSignal) {
|
||||
valuesToSet.Intent_signals__c = intentSignal;// eslint-disable-line camelcase
|
||||
}
|
||||
|
||||
let existingContactRecord;
|
||||
// Search for an existing Contact record using the provided email address or linkedIn profile URL.
|
||||
|
|
@ -134,6 +145,21 @@ module.exports = {
|
|||
if(description && existingContactRecord.Description) {
|
||||
valuesToSet.Description = existingContactRecord.Description + '\n' + description;
|
||||
}
|
||||
// If an intent signal was specified, add it to the list of intent signals on the exisitng contact.
|
||||
// Note: intent signals values are stored as a single string in salesforce, separated by a semicolon.
|
||||
if(intentSignal && existingContactRecord.Intent_signals__c) {
|
||||
// Convert the string from the Salesforce record into an array.
|
||||
let existingContactIntentSignalsAsAnArray = existingContactRecord.Intent_signals__c.split(';');
|
||||
// If this intent signal is not included in the exisitng contacts intent signals, add it.
|
||||
if(!existingContactIntentSignalsAsAnArray.includes(intentSignal)) {
|
||||
existingContactIntentSignalsAsAnArray.push(intentSignal);
|
||||
// Convert the array back into a string to send it to Salesforce.
|
||||
valuesToSet.Intent_signals__c = existingContactIntentSignalsAsAnArray.join(';');// eslint-disable-line camelcase
|
||||
} else {
|
||||
// Otherwise, if the existing contact already has this intent signal tracked, remove it from the valuesToSet
|
||||
delete valuesToSet.Intent_signals__c;
|
||||
}
|
||||
}
|
||||
// Check the existing contact record's psychologicalStage.
|
||||
if(psychologicalStage) {
|
||||
let recordsCurrentPsyStage = existingContactRecord.Stage__c;
|
||||
|
|
|
|||
Loading…
Reference in a new issue