Chord OMS
...
SDK Reference
useAnalytics
18 min
the useanalytics hook returns a set of functions that send a tracking event to segment the starter sends most segment events about user actions automatically, when other hooks like usecart are used however, some events need to be closely tied to the ui, like click tracking, and must be sent explicitly by react components functions for sending these events are available via the useanalytics hook example import { useanalytics } from ' /hooks/actions' const { trackcartviewed, trackcollectionclicked, trackemailcaptured, trackproductclicked, trackproductlistfiltered, trackproductlistviewed, trackproductviewed, trackpromotionclicked, trackpromotionviewed, trackstockrequestcreated } = useanalytics() returns the useanalytics hook returns an object with these properties 249,494 trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type functions trackcartviewed the trackcartviewed function sends a cart viewed event to segment arguments none returns undefined example import { useanalytics } from ' /hooks/actions' const { trackcartviewed } = useanalytics() trackcartviewed() trackcollectionclicked the trackcollectionclicked function sends a collection clicked event to segment arguments trackcollectionclicked({ id, description, imageurl, slug, title }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackcollectionclicked } = useanalytics() trackcollectionclicked({ id 'red collection', title 'red' }) trackemailcaptured the trackemailcaptured function sends an email captured event to segment arguments trackemailcaptured({ email, placement }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackemailcaptured } = useanalytics() trackemailcaptured({ email 'test\@test com', placement { component 'footer', page '/shop' } }) trackproductclicked the trackproductclicked function sends a product clicked event to segment arguments trackproductclicked({ producthandle }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { productclicked } = useanalytics() trackproductclicked({ producthandle 'product 1' }) trackproductlistfiltered the trackproductlistfiltered function sends a product list filtered event to segment arguments trackproductlistfiltered({ filter, list, sort }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackproductlistfiltered } = useanalytics() trackproductlistfiltered({ filter { type 'color', value 'red' }, list { category 'shirt', id '123' }, sort { type 'ascending', value 'price' } }) trackproductlistviewed the trackproductlistviewed function sends a product list viewed event to segment arguments trackproductlistviewed({ list }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackproductlistviewed } = useanalytics() trackproductlistviewed({ list { category 'shirt', id '123' } }) trackproductviewed the trackproductviewed function sends a product viewed event to segment arguments trackproductviewed({ producthandle }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackproductviewed } = useanalytics() trackproductviewed({ producthandle 'product 1' }) trackpromotionclicked the trackpromotionclicked function sends a promotion clicked event to segment arguments trackpromotionclicked({ creative, id, name, position }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackpromotionclicked } = useanalytics() trackpromotionclicked({ creative 'apple', id '123', name 'red shirt sale', position 'banner' }) trackpromotionviewed the trackpromotionviewed function sends a promotion viewed event to segment arguments trackpromotionviewed({ creative, id, name, position }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackpromotionviewed } = useanalytics() trackpromotionviewed({ creative 'apple', id '123', name 'red shirt sale', position 'banner' }) trackstockrequestcreated the trackstockrequestcreated function sends a stock request created event to segment arguments trackstockrequestcreated({ email, producthandle }) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns undefined example import { useanalytics } from ' /hooks/actions' const { trackstockrequestcreated } = useanalytics() trackstockrequestcreated({ email 'test\@test com', producthandle 'product 1' })