Individual visitor message

Set a message 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 Website Message (WebSite_Message__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('WebSite_Message__c'). However we only want to act once when this value is changed, so we can subscribe to the send2crmDataChanged event.

window.addEventListener('send2crmDataChanged', (evt) => { // Don't bother the visitor with empty messages. if (!evt.detail.new.WebSite_Message__c) return; if (evt.detail.old.WebSite_Message__c != evt.detail.new.WebSite_Message__c) { // Message has changed, display it to the visitor. alert(evt.detail.new.WebSite_Message__c); } });

Persistent message

As an alternative you may wish for the message to remain, perhaps with an option to dismiss. In this case we can use a standard event like load.

window.addEventListener('load', (evt) => { // Get personalized message from visitor data. let message = send2crm.personalization.getData('WebSite_Message__c'); if (!message) return; // No message. // Optional; if we want to know when the visitor has dismissed, // we can store a value directly in the same visitor data. (See below to set). if (!send2crm.personalization.getData('Website_Message_Dismissed')) { // Website-specific; perhaps use a third-party popup that is less intrusive // or simply display in a message area on the page. document.querySelector('#message_text')?.innerHTML = message; } });

To set the flag for dismissing the message on button click:

dismissBtn.addEventListener('click', (evt) => { send2crm.personalization.setData('Website_Message_Dismissed', true); });

We can also remove the dismiss flag when a new message is set:

Although there is no intermediate service between the Send2CRM client and service, it may still be a good idea to sanitize any HTML used directly to avoid XSS attacks.

Extended use

The Send2CRM service can return almost any field values for personalization use. Further possibilities include:

  • Provide direct links to locations within the website, or to third party resources.

  • Give access to non-public resources by providing security tokens.

  • Multiple fields can be set, this might include the visitor’s name if available to really personalize the message.

  • Set a custom landing page for specific visitors.

  • Combine with immediate personalization for real-time actions.

  • Send the dismiss flag back to Salesforce so sales reps can see when visitors have viewed their message. For example, raise a custom event and create a Flow or trigger in Salesforce that reacts when the corresponding record in the send2crm__s2cSessionStat__c is inserted or updated.

  • Advanced custom handling via automation events.