/
Record a Search event

Record a Search event

Raise a custom event when a visitor uses a search mechanism on the website.

Consider the following example search form:

<form id="search-form" action="/search"> <input type="text" name="q" /> </form>

A Send2CRM event could be raised each time this is submitted by using the following script:

let searchForm = document.querySelector('form#search-form'); if (searchForm) { // Attach an event listener to the search form. searchForm.addEventListener('submit', (evt) => { // Don't submit just yet. evt.preventDefault(); // Get search text. let searchTextVal = searchForm.querySelector('input[name="q"]')?.value; if (searchTextVal) { // TODO: sanitize or least truncate long searchText before adding to the event? // Raise a custom Send2CRM session event. send2crm?.analytics?.setCustomEvent('WEBSEARCH', { searchText: searchTextVal }); // Submit the form now. searchForm.submit(); } }); }

All events are included in identified visitor updates to Salesforce.

Related content

Goals from key words
Goals from key words
Read with this
Custom event from URL parameter
Custom event from URL parameter
More like this
Session Events
More like this
Automation Events
Automation Events
More like this
Filter form submissions
Filter form submissions
More like this
Personalization events
Personalization events
More like this