File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ import { useAppSdk } from './useAppSdk' ;
2+
3+ const useAnalytics = ( ) => {
4+ const [ appSdk ] = useAppSdk ( ) ;
5+
6+ const trackEvent = ( event : string , eventData : any = { } ) => {
7+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
8+ // @ts -ignore
9+ return appSdk ?. pulse ( event , eventData ) ;
10+ } ;
11+
12+ return { trackEvent } ;
13+ } ;
14+
15+ export default useAnalytics ;
Original file line number Diff line number Diff line change 1+ /**
2+ * useAppSdk
3+ * @return the appSdk instance after initialization
4+ * This hook is to utilize for appSdk pulse method and its an exception for dev tools app.
5+ */
6+ import { atom , useAtom } from 'jotai' ;
7+ import Extension from '@contentstack/app-sdk/dist/src/extension' ;
8+
9+ export const appSdkRefAtom = atom < Extension | null > ( null ) ;
10+
11+ /**
12+ * Getter and setter for appSdk instance.
13+ * To be used during Sdk initialization
14+ */
15+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16+ export const useAppSdk = ( ) : [ Extension | null , any ] => {
17+ return useAtom ( appSdkRefAtom ) ;
18+ } ;
You can’t perform that action at this time.
0 commit comments