You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Discussed possible approaches for this refactor with @artemis-prime. We want to clean up the code and reduce analytics boilerplate inside UI components. So we are proposing the following approach:
Create an analytics folder in root of hanzo/commerce. In this folder add send.ts file:
declare global {interfaceWindow{fbq: Function;gtag: Function;}}// https://developers.facebook.com/docs/meta-pixel/referenceconstsendFBEvent=(name: string,options={})=>{window.fbq('track',name,options);}// https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtagconstsendGAEvent=(name: string,options={})=>{window.gtag('event',name,options);}export{sendFBEvent,sendGAEvent}
in index.ts export a separate function for each event type, for example trackPurchase, trackAddToCart, trackAddShippingInfo... Separate the code for each event type into it's own file.
Do the same inside hanzo/auth for trackLogin.
Keep analytics initialization scripts in hanzo/common.
We considered creating a new module hanzo/analytics, however to avoid circular dependencies between hanzo/analytics and hanzo/commerce we decided against it.
Create analytics service in
hanzo/commerce
with handlers for events:Create an analytics service in
hanzo/auth
with handlers for events:For example, instead of this:
we will have this:
The text was updated successfully, but these errors were encountered: