Skip to content

Commit

Permalink
Website: Track reason behind psychological stage changes in start flo…
Browse files Browse the repository at this point in the history
…w. (#21483)

Changes:
- Updated the `update-or-create-contact-and-account` helper to support a
new input: `psychologicalStageChangedBy`, and to set the provided value
on contact records.
- Updated `save-questionnaire-progress` to set a
psychologicalStageChangedBy value when updating contact records.
  • Loading branch information
eashaw committed Aug 24, 2024
1 parent acbdc24 commit b18f60c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions website/api/controllers/save-questionnaire-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ module.exports = {
}
// Only update CRM records if the user's psychological stage changes.
if(psychologicalStage !== userRecord.psychologicalStage) {
let psychologicalStageChangeReason = 'Website - Organic start flow'; // Default psystageChangeReason to "Website - Organic start flow"
if(this.req.session.adAttributionString && this.req.session.visitedSiteFromAdAt) {
let thirtyMinutesAgoAt = Date.now() - (1000 * 60 * 30);
// 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 > thirtyMinutesAgoAt) {
psychologicalStageChangeReason = this.req.session.adAttributionString;
}
}
// Update the psychologicalStageLastChangedAt timestamp if the user's psychological stage
psychologicalStageLastChangedAt = Date.now();
sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
Expand All @@ -212,6 +220,7 @@ module.exports = {
primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined,
organization: this.req.me.organization,
psychologicalStage,
psychologicalStageChangeReason,
getStartedResponses: questionnaireProgressAsAFormattedString,
contactSource: 'Website - Sign up',
}).exec((err)=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module.exports = {
'6 - Has team buy-in'
]
},
psychologicalStageChangeReason: {
type: 'string',
example: 'Website - Organic start flow'
},
contactSource: {
type: 'string',
isIn: [
Expand All @@ -56,7 +60,7 @@ module.exports = {
},


fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, contactSource, description, getStartedResponses}) {
fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, psychologicalStageChangeReason, contactSource, description, getStartedResponses}) {
// Return undefined if we're not running in a production environment.
if(sails.config.environment !== 'production') {
sails.log.verbose('Skipping Salesforce integration...');
Expand Down Expand Up @@ -106,6 +110,9 @@ module.exports = {
if(description) {
valuesToSet.Description = description;
}
if(psychologicalStageChangeReason) {
valuesToSet.Psystage_change_reason__c = psychologicalStageChangeReason;// eslint-disable-line camelcase
}

let existingContactRecord;
// Search for an existing Contact record using the provided email address or linkedIn profile URL.
Expand Down
11 changes: 11 additions & 0 deletions website/api/hooks/custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ will be disabled and/or hidden in the UI.
res.locals.me = undefined;
}//fi

// Check for query parameters set by ad clicks.
// This is used to track the reason behind a psychological stage change.
// If the user performs any action that causes a stage change
// within 30 minutes of visiting the website from an ad, their psychological
// stage change will be attributed to the ad campaign that brought them here.
if(req.param('utm_source') && req.param('creative_id') && req.param('campaign_id')){
req.session.adAttributionString = `${req.param('utm_source')} ads - ${req.param('campaign_id')} - ${_.trim(req.param('creative_id'), '?')}`;// Trim questionmarks from the end of creative_id parameters.
// Example adAttributionString: Linkedin - 1245983829 - 41u3985237
req.session.visitedSiteFromAdAt = Date.now();
}

// Check for website personalization parameter, and if valid, absorb it in the session.
// (This makes the experience simpler and less confusing for people, prioritizing showing things that matter for them)
// [?] https://en.wikipedia.org/wiki/UTM_parameters
Expand Down

0 comments on commit b18f60c

Please sign in to comment.