Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website: Add website visit reason to page view records. #23154

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions website/api/hooks/custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,22 @@ 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')
.create({
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}`);
Expand Down
Loading