mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Website: Add website visit reason to page view records. (#23154)
Closes: #23107 Changes: - Updated the custom hook to send `adAttributionString` to Fleet website page view records if that value was set in a logged-in user's session <30m before they visit a page.
This commit is contained in:
parent
dd8986d467
commit
9d69f01c2b
1 changed files with 9 additions and 0 deletions
9
website/api/hooks/custom/index.js
vendored
9
website/api/hooks/custom/index.js
vendored
|
|
@ -311,6 +311,14 @@ will be disabled and/or hidden in the UI.
|
|||
await salesforceConnection.login(sails.config.custom.salesforceIntegrationUsername, sails.config.custom.salesforceIntegrationPasskey);
|
||||
let today = new Date();
|
||||
let nowOn = today.toISOString().replace('Z', '+0000');
|
||||
let websiteVisitReason;
|
||||
if(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 websiteVisitReason to be the adAttributionString stored in their session.
|
||||
if(req.session.visitedSiteFromAdAt > thirtyMinutesAgoAt) {
|
||||
websiteVisitReason = this.req.session.adAttributionString;
|
||||
}
|
||||
}
|
||||
// Create the new Fleet website page view record.
|
||||
return await sails.helpers.flow.build(async ()=>{
|
||||
return await salesforceConnection.sobject('fleet_website_page_views__c')
|
||||
|
|
@ -318,6 +326,7 @@ will be disabled and/or hidden in the UI.
|
|||
Contact__c: recordIds.salesforceContactId,// eslint-disable-line camelcase
|
||||
Page_URL__c: `https://fleetdm.com${req.url}`,// eslint-disable-line camelcase
|
||||
Visited_on__c: nowOn,// eslint-disable-line camelcase
|
||||
Website_visit_reason__c: websiteVisitReason// eslint-disable-line camelcase
|
||||
});
|
||||
}).intercept((err)=>{
|
||||
return new Error(`Could not create new Fleet website page view record. Error: ${err}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue