Website: Update CRM helper and usage (#23670)

Changes:
- Updated the update-or-create-contact-and-account helper to update
created contact records with a psychological stage
- Updated places where we were using the
update-or-create-contact-and-account helper to set a contact source on
new records.
This commit is contained in:
Eric 2024-11-11 12:35:49 -06:00 committed by GitHub
parent e1b28eadc2
commit 2d8ebb4388
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 9 deletions

View file

@ -169,6 +169,7 @@ module.exports = {
firstName: this.req.me.firstName,
lastName: this.req.me.lastName,
organization: this.req.me.organization,
contactSource: 'Website - Sign up',// Note: this is only set on new contacts.
description: `Purchased a self-service Fleet Premium license on ${isoTimestampForDescription.split('T')[0]} for ${quoteRecord.numberOfHosts} host${quoteRecord.numberOfHosts > 1 ? 's' : ''}.`
}).exec((err)=>{
if(err){

View file

@ -138,13 +138,21 @@ the account verification message.)`,
.intercept({name: 'UsageError'}, 'invalid')
.fetch();
let psychologicalStageChangeReason;
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: newEmailAddress,
firstName: firstName,
lastName: lastName,
organization: organization,
contactSource: 'Website - Sign up'
contactSource: 'Website - Sign up',
psychologicalStageChangeReason,
}).exec((err)=>{
if(err){
sails.log.warn(`Background task failed: When a user (email: ${newEmailAddress} signed up for a fleetdm.com account, a Contact and Account record could not be created/updated in the CRM.`, err);

View file

@ -110,18 +110,12 @@ module.exports = {
if(primaryBuyingSituation) {
valuesToSet.Primary_buying_situation__c = primaryBuyingSituation;// eslint-disable-line camelcase
}
if(psychologicalStage) {
valuesToSet.Stage__c = psychologicalStage;// eslint-disable-line camelcase
}
if(getStartedResponses) {
valuesToSet.Website_questionnaire_answers__c = getStartedResponses;// eslint-disable-line camelcase
}
if(description) {
valuesToSet.Description = description;
}
if(psychologicalStageChangeReason) {
valuesToSet.Psystage_change_reason__c = psychologicalStageChangeReason;// eslint-disable-line camelcase
}
if(intentSignal) {
valuesToSet.Intent_signals__c = intentSignal;// eslint-disable-line camelcase
}
@ -145,6 +139,13 @@ module.exports = {
if(description && existingContactRecord.Description) {
valuesToSet.Description = existingContactRecord.Description + '\n' + description;
}
// If we're updating a contact, add psychologicalStage and psychologicalStageChangeReason to the dictionary of valuesToSet.
if(psychologicalStage) {
valuesToSet.Stage__c = psychologicalStage;// eslint-disable-line camelcase
}
if(psychologicalStageChangeReason) {
valuesToSet.Psystage_change_reason__c = psychologicalStageChangeReason;// eslint-disable-line camelcase
}
// 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) {
@ -260,6 +261,7 @@ module.exports = {
}
// console.log(`creating new Contact record.`)
// Create a new Contact record for this person.
let newContactRecord = await salesforceConnection.sobject('Contact')
.create({
AccountId: salesforceAccountId,
@ -268,8 +270,17 @@ module.exports = {
LastName: lastName ? lastName : '?',
...valuesToSet,
});
// console.log(`Created ${newContactRecord.id}`);
salesforceContactId = newContactRecord.id;
// Since we've created a new contact, we'll update the psychological stage to be either '2 - Aware', or whatever psystage was provided.
// This causes it to appear as an edit in our CRM and helps reporting.
await salesforceConnection.sobject('Contact')
.update({
Id: salesforceContactId,
Stage__c: psychologicalStage ? psychologicalStage : '2 - Aware',// eslint-disable-line camelcase
Psystage_change_reason__c: psychologicalStageChangeReason ? psychologicalStageChangeReason : null,// eslint-disable-line camelcase
});
// console.log(`Created ${newContactRecord.id}`);
}//fi
return {

View file

@ -302,6 +302,7 @@ will be disabled and/or hidden in the UI.
firstName: sanitizedUser.firstName,
lastName: sanitizedUser.lastName,
organization: sanitizedUser.organization,
contactSource: 'Website - Sign up',// Note: this is only set on new contacts.
});
let jsforce = require('jsforce');
// login to Salesforce