Interfaces
Interface: UseAnalytics
module react autonomy docid\ zoz6w56ubppacr0po0gls useanalytics useanalytics contains the tracking functions returned by function useanalytics docid\ nepfhdl3o3ellgnk098cu properties chordanalytics • chordanalytics analyticsclient this provides low level access to chord's analytics client defined in packages/react autonomy/src/hooks/use analytics ts 87 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use analytics ts#l87 trackcartviewed • trackcartviewed ( options? type alias trackcartviewed docid 40dhmvaemhol06uci6qoe ) => { payload type alias trackcartviewed docid 40dhmvaemhol06uci6qoe = options; type string = track cart viewed } type declaration ▸ ( options? ) object the trackcartviewed function sends a cart viewed event to segment you should call this function when the cart page is viewed import { useanalytics, usecart } from '@chordcommerce/react autonomy' import { useeffect } from 'react' const cartpage = () => { const { cart, loadcart, isloaded, isfetching } = usecart() const { trackcartviewed } = useanalytics() useeffect(() => { if (!isloaded && !isfetching) { loadcart() catch(error => console error('could not loadcart', error)) } }, \[loadcart, isloaded, isfetching]) useeffect(() => { if (isloaded) { trackcartviewed({ products cart? lineitems ?? \[] }) } // only track isloaded so that this only fires once // eslint disable next line react hooks/exhaustive deps }, \[isloaded]) // return cart page } parameters name type options? type alias trackcartviewed docid 40dhmvaemhol06uci6qoe returns object name type payload type alias trackcartviewed docid 40dhmvaemhol06uci6qoe type string defined in packages/react autonomy/src/hooks/use analytics ts 123 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use analytics ts#l123 trackcollectionclicked • trackcollectionclicked ( options type alias trackcollectionclicked docid\ et3gmg9ipchqkim plmfm ) => { payload type alias trackcollectionclicked docid\ et3gmg9ipchqkim plmfm = options; type string = track collection clicked } type declaration ▸ ( options ) object the trackcollectionclicked function fires a collection clicked event to segment you should call this function when the user clicks on a link to a collection import { useanalytics } from '@chordcommerce/react autonomy' const collectionlink = ({ collection, children }) => { const { trackcollectionclicked } = useanalytics() const url = `/shop/?collection=${slug}` return ( \<a href={url} onclick={() => trackcollectionclicked({ collection })}> {children} \</a> ) } parameters name type options type alias trackcollectionclicked docid\ et3gmg9ipchqkim plmfm returns object name type payload type alias trackcollectionclicked docid\ et3gmg9ipchqkim plmfm type string defined in packages/react autonomy/src/hooks/use analytics ts 146 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use analytics ts#l146 trackemailcaptured • trackemailcaptured ( options interface trackemailcaptured docid\ t0bhcykwau9ztsabnjwpa ) => { payload interface trackemailcaptured docid\ t0bhcykwau9ztsabnjwpa = options; type string = track email captured } type declaration ▸ ( options ) object the trackemailcaptured function sends a email captured event to segment you should call this whenever the user enters an email examples of this can include newsletter signups, coupon pop ups and/or logins this function will also identify the user https //segment com/docs/connections/spec/identify/ to segment so that all subsequent tracking calls will be associated with this email import { useanalytics } from ' /hook/actions' const newsletterform = () => { const { trackemailcaptured } = useanalytics() const handlesubmit = usecallback((event) => { event preventdefault() const payload = { email event currenttarget elements\['email'] value, component 'footer', page 'sitewide', website window\ location host, } trackemailcaptured(payload) }, \[trackemailcaptured]) return ( \<form onsubmit={handlesubmit}> \<p>sign up for our newsletter!\</p> \<input type="email" name="email" placeholder="your email" required /> \<button type="submit">sign up\</button> \</form> ) } parameters name type options interface trackemailcaptured docid\ t0bhcykwau9ztsabnjwpa returns object name type payload interface trackemailcaptured docid\ t0bhcykwau9ztsabnjwpa type string defined in packages/react autonomy/src/hooks/use analytics ts 185 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use analytics ts#l185 trackproductclicked • trackproductclicked ( options interface trackproductclicked docid\ pqv9urqhjpvhy60krdch0 ) => { payload interface trackproductclicked docid\ pqv9urqhjpvhy60krdch0 = options; type string = track product clicked } type declaration ▸ ( options ) object the trackproductclicked function sends a product clicked event to segment you should call this function when the user clicks on a link to a product import { useanalytics } from '@chordcommerce/react autonomy' const productlink = ({ children, product }) => { const { trackproductclicked } = useanalytics() const url = `/products/${slug}/` return ( \<a href={url} onclick={() => trackproductclicked({ product })}> {children} \</a> ) } parameters name type options interface trackproductclicked docid\ pqv9urqhjpvhy60krdch0 returns object name type payload interface trackproductclicked docid\ pqv9urqhjpvhy60krdch0 type string defined in packages/react autonomy/src/hooks/use analytics ts 229 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use analytics ts#l229 trackproductviewed • trackproductviewed ( options type alias trackproductviewed docid\ awh6k6bkjhs0et5zi1mlt ) => { payload type alias trackproductviewed docid\ awh6k6bkjhs0et5zi1mlt = options; type string = track product viewed } type declaration ▸ ( options ) object the trackproductviewed function fires a product viewed event to segment you should call this function when a product page is opened import { useanalytics } from '@chordcommerce/gatsby theme autonomy' export default (product) => { const { trackproductviewed } = useanalytics() useeffect(() => { trackproductviewed({ product }) }, \[product]) // return product page } parameters name type options type alias trackproductviewed docid\ awh6k6bkjhs0et5zi1mlt returns object name type payload type alias trackproductviewed docid\ awh6k6bkjhs0et5zi1mlt type string defined in packages/react autonomy/src/hooks/use analytics ts 206 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use analytics ts#l206 trackvariantclicked • trackvariantclicked ( options interface trackvariantclicked docid 1ey3n9cgavjdqj26h3sgu ) => { payload interface trackvariantclicked docid 1ey3n9cgavjdqj26h3sgu = options; type string = track variant clicked } type declaration ▸ ( options ) object the trackvariantclicked function sends a variant clicked event to segment you should call this function when the user clicks on a link to this function takes a product and not a variant import { useanalytics } from '@chordcommerce/react autonomy' const productlink = ({ children, product }) => { const { trackvariantclicked } = useanalytics() const url = `/products/${slug}/` return ( \<a href={url} onclick={() => trackvariantclicked({ product })}> {children} \</a> ) } parameters name type options interface trackvariantclicked docid 1ey3n9cgavjdqj26h3sgu returns object name type payload interface trackvariantclicked docid 1ey3n9cgavjdqj26h3sgu type string defined in packages/react autonomy/src/hooks/use analytics ts 253 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use analytics ts#l253