@@ -11,15 +11,25 @@ import tippy from "tippy.js";
1111import localeTexts from "../../common/locale/en-us" ;
1212import constants from "../../common/constants" ;
1313import { mergeObjects } from "../../common/utils" ;
14- import TrackJS from "../../trackjs" ;
1514import { TypeAppSdkConfigState } from "../../common/types" ;
1615
1716/* Import node module CSS */
1817import "tippy.js/dist/tippy.css" ;
1918/* Import our CSS */
2019import "./styles.scss" ;
2120
21+ import useJsErrorTracker from "../../hooks/useJsErrorTracker" ;
22+ import { useAppSdk } from "../../hooks/useAppSdk" ;
23+ import useAnalytics from "../../hooks/useAnalytics" ;
24+
2225const ConfigScreen : React . FC = function ( ) {
26+
27+ // error tracking hooks
28+ const { addMetadata, trackError } = useJsErrorTracker ( ) ;
29+ const { trackEvent } = useAnalytics ( ) ;
30+ const [ appSdk ] = useAppSdk ( ) ;
31+
32+
2333 const [ state , setState ] = useState < TypeAppSdkConfigState > ( {
2434 installationData : {
2535 configuration : {
@@ -35,14 +45,11 @@ const ConfigScreen: React.FC = function () {
3545 } ,
3646 appSdkInitialized : false ,
3747 } ) ;
38- const [ isStringified , setIsStringified ] = useState ( false ) ;
48+ const [ isStringified , setIsStringified ] = useState ( false ) ;
3949
4050 useEffect ( ( ) => {
4151 ContentstackAppSdk . init ( )
4252 . then ( async ( appSdk ) => {
43- //Adding Track.js metadata
44- TrackJS . addMetadata ( appSdk ) ;
45-
4653 const sdkConfigData = appSdk ?. location ?. AppConfigWidget ?. installation ;
4754 if ( sdkConfigData ) {
4855 const installationDataFromSDK =
@@ -63,6 +70,7 @@ const ConfigScreen: React.FC = function () {
6370 }
6471 } )
6572 . catch ( ( error ) => {
73+ trackError ( error ) ;
6674 console . error ( constants . appSdkError , error ) ;
6775 } ) ;
6876 } , [ ] ) ;
@@ -77,10 +85,8 @@ const ConfigScreen: React.FC = function () {
7785 if ( typeof fieldValue === "string" ) fieldValue = fieldValue ?. trim ( ) ;
7886 const updatedConfig = state ?. installationData ?. configuration || { } ;
7987 const updatedServerConfig = state ?. installationData ?. serverConfiguration ;
80-
8188 if ( fieldName === "auth_token" ) updatedServerConfig [ fieldName ] = fieldValue ;
8289 else updatedConfig [ fieldName ] = fieldValue ;
83-
8490 if ( typeof state ?. setInstallationData !== "undefined" ) {
8591 await state ?. setInstallationData ( {
8692 ...state ?. installationData ,
@@ -94,6 +100,7 @@ const ConfigScreen: React.FC = function () {
94100
95101 const updateCustomJSON = ( e : any ) => {
96102 const val = e ?. target ?. id !== "jsonObject" ;
103+ trackEvent ( "Clicked" , { property : `Update Json` } ) ;
97104 setIsStringified ( val ) ;
98105 updateConfig ( { target : { name : "isStringified" , value : val } } ) ;
99106 } ;
0 commit comments