Custom landing page

Set a custom landing page for an identified visitor based on a field value in Salesforce.

  1. Determine an appropriate field to use on the related object in Salesforce. For example if visitors are identified as Leads, add a custom Visitor Landing Page (Visitor_Landing_Page__c) field to Lead.

  2. Update the form mapping in Salesforce to include the desired field with the Personalize option checked. Now the field value will be sent back to the Send2CRM client each time a visitor update is performed.

  3. The field value will now be available via send2crm.personalization.getData('Visitor_Landing_Page__c').

Perform redirect

For this example we are going to assume that the redirect will only be performed from the home page, and only once per session. We’ll use the standard load event.

window.addEventListener('load', (evt) => { // Get personalized landing page from visitor data. let redirect = send2crm.personalization.getData('Visitor_Landing_Page__c'); // For security reasons, we only accept pages on our website. let baseUrl = window.location.protocol + '//' + window.location.host; if (!redirect || !redirect.startsWith(baseUrl)) return; // Use a session storage value to determine whether we've already redirected. // Otherwise the visitor won't be able to view the main home page at all. let isRedirected = sessionStorage.getItem('isRedirected'); if (!isRedirected) { // Set flag and perform the redirect. sessionStorage.setItem('isRedirected', true); window.location.href = redirect; } });

We can also handle immediate changes when a new landing page is set:

window.addEventListener('send2crmDataChanged', (evt) => { if (evt.detail.old.Visitor_Landing_Page__c != evt.detail.new.Visitor_Landing_Page__c) { // Landing page has changed, clear the flag. sessionStorage.setItem('isRedirected', false); } });

Don’t forget to validate the redirect URL.