Tracking search events
November 30, 2024
This example assumes that you already have a jExperience, jCustomer environment installed and configured, as well as kibana dashboard provider and jExperience dashboards.
Sending the search event
Since jExperience 3.5, search events need to be sent explicitly using some JavaScript code:
// Variables that will be used const searchTerm = 'mySearchTerm'; const formName = 'searchForm'; const targetType = 'search';
// Check if wem object, used for data collection is available if (!window.wem ) { console.warn('[Collecting search event] window.wem is missing'); }
// Build the event const searchEvent = window.wem.buildEvent('search', window.wem.buildTarget(formName, targetType), window.wem.buildSourcePage() ); searchEvent.properties = { originForm: targetId, language: window.digitalData?.page.pageInfo.language, keyword: searchTerm, origin: location.pathname };
// Send the event to jCustomer window.wem.collectEvent(searchEvent, () => console.debug('[Collecting search event] search formEvent sent'), () => console.debug('[Collecting search event] oups search formEvent was not handled properly') );
Verifying that the search event is correctly collected
From your live website, do a couple of searches.
From the Jahia UI, Go to jExperience => Global => Dashboards => Internal Site Searches
Find the visualization "Internal Site Searches Data Table" and verify that you searches appear correctly.