Chord OMS
...
Gatsby
SDK Reference

useAnalytics

11min
the useanalytics hook returns a series of methods that fire a tracking event to segment, our integrated customer data platform most segment tracking is done automatically by the sdk for example, when you use the addtocart method (see usecart ), a corresponding track api call to segment is made however, some track calls need to be closely tied to the ui, as in the case of tracking clicks on elements, and these calls need to be explicitly made from your react components methods for making these calls are available via the useanalytics hook and listed below import { useanalytics } from '@chordcommerce/gatsby theme performance' const { trackcartviewed, trackcollectionclicked, trackemailcaptured, trackproductclicked, trackproductlistfiltered, trackproductlistviewed, trackproductviewed, trackpromotionclicked, trackpromotionviewed, trackstockrequestcreated } = useanalytics() trackcartviewed() results in a cart viewed track event in segment example trackcartviewed() trackcollectionclicked() results in a collection clicked track event in segment example trackcollectionclicked({ id, description, imageurl, slug, title }) trackemailcaptured() results in a email captured track event in segment example trackemailcaptured({ email 'test\@test com', placement 'footer' }) trackproductclicked() results in a product clicked track event in segment example trackproductclicked({ producthandle 'product 1' }) trackproductlistfiltered() results in a product list filtered track event in segment example trackproductlistfiltered({ filter { type 'color', value 'red' }, list { category 'shirt', id '123' }, sort { type 'ascending', value 'price' } }) trackproductlistviewed() results in a product list viewed track event in segment example trackproductlistviewed({ list { category 'shirt', id '123' } }) trackproductviewed() results in a product viewed track event in segment example trackproductviewed({ producthandle 'product 1' }) trackpromotionclicked() results in a promotion clicked track event in segment example trackpromotionclicked({ creative 'apple', id '123', name 'red shirt sale', position 'banner' }) trackpromotionviewed() results in a promotion viewed track event in segment example trackpromotionclicked({ creative 'apple', id '123', name 'red shirt sale', position 'banner' }) trackstockrequestcreated() results in a stock request created track event in segment example trackstockrequestcreated({ email 'test\@test com' producthandle 'product 1' })