@@ -19,28 +19,6 @@ const mixpanel = require("mixpanel").init("12fa2800ccbf44a5c36c37bc9776e4c0", {
19
19
protocol : "https"
20
20
} ) ;
21
21
22
- //console.log("MP ", Object.keys(mixpanel));
23
- //attempt to read cookies
24
- const user = new MPID ( ) ;
25
-
26
- //set current user cookie if it does not exist in cookies;
27
- if ( user . checkDocumentCookie ( document ) ) {
28
- console . log ( "Reactime cookie found " ) ;
29
- user . getCookie ( ) ;
30
- mixpanel . people . increment ( user . get_dId ( ) , "times" ) ;
31
- } else {
32
- console . log ( "No reactime cookie found. Attempting set cookie." ) ;
33
- user . setCookie ( ) ;
34
- mixpanel . people . set ( user . get_dId ( ) , { "times" : 1 } ) ;
35
- }
36
-
37
-
38
-
39
- function mpClickTrack ( e ) {
40
- mixpanel . track ( "click" , { distinct_id : user . distinct_id , where : e ?. target ?. innerText } ) ;
41
- } ;
42
-
43
- document . addEventListener ( "click" , mpClickTrack ) ;
44
22
45
23
46
24
function MainContainer ( ) : any {
@@ -95,6 +73,42 @@ function MainContainer(): any {
95
73
dispatch ( setPort ( port ) ) ;
96
74
} ) ;
97
75
76
+ /**
77
+ * get set cookies for mixpanel analytics
78
+ **/
79
+ useEffect ( ( ) => {
80
+ //console.log("MP ", Object.keys(mixpanel));
81
+ //attempt to read cookies
82
+ const user = new MPID ( ) ;
83
+ /**
84
+ * If developing turn tracking off by setting user.debug to true;
85
+ * End goal: set user.debug variable in npm run dev
86
+ */
87
+ user . debug = true ;
88
+
89
+ if ( ! user . debug ) {
90
+ //set current user cookie if it does not exist in cookies;
91
+ if ( user . checkDocumentCookie ( document ) ) {
92
+ user . getCookie ( ) ;
93
+ mixpanel . people . increment ( user . get_dId ( ) , "times" ) ;
94
+ } else {
95
+ user . setCookie ( ) ;
96
+ mixpanel . people . set ( user . get_dId ( ) , { times : 1 } ) ;
97
+ }
98
+ }
99
+
100
+ function mpClickTrack ( e ) {
101
+ if ( ! user . debug ) {
102
+ mixpanel . track ( "click" , {
103
+ distinct_id : user . distinct_id ,
104
+ where : e ?. target ?. innerText ,
105
+ } ) ;
106
+ }
107
+ }
108
+
109
+ document . addEventListener ( "click" , mpClickTrack ) ;
110
+ } , [ ] )
111
+
98
112
if ( ! tabs [ currentTab ] ) {
99
113
return (
100
114
< div className = "error-container" >
0 commit comments