codemanas / cm-typesense-docs

Documentation for Typesense Plugin
8 stars 0 forks source link

JavaScript hooks #10

Closed remoteboy closed 3 months ago

remoteboy commented 4 months ago

Are there any events triggered in JavaScript that I can hook into? I have two things I'd like to achieve

  1. analytics integration - everytime a user searches for a term, or clicks on a link I'd like to send some data to our GA property
  2. alternate trigger for launching the Instant Search box. Currently I'm using the 'Replace WordPress Search' option but ideally i'd like to just have a search icon that i can click on to launch the Instant Search box.
digamber89 commented 4 months ago

Hi @remoteboy ,

  1. For analytics please use the custom event cmswt_search_state_changed as suggested it run when the search state changes
  2. For alternate trigger that is already supported via Trigger - this will trigger the popup.
remoteboy commented 3 months ago

Thanks - got the Trigger working but not sure how to hook into the cmswt_search_state_changed event?

digamber89 commented 3 months ago

Please check this.

document.addEventListener('cmswt_search_state_changed', function(eventState){
      if( eventState === undefined) return;
      const {detail:state} = eventState;
      console.log('State of Search',state)
  });
remoteboy commented 3 months ago

Thanks - that works a treat.