@@ -20,7 +20,14 @@ const MIXPANEL_TOKEN = '3cc6dbdcb34ee3957202eda8395b58aa';
2020
2121let isInitialized = false ;
2222
23+ const isLocalhost = window . location . hostname === 'localhost' || window . location . hostname === '127.0.0.1' ;
24+
2325const initMixPanel = ( ) => {
26+ if ( isLocalhost ) {
27+ console . log ( 'Mixpanel disabled on localhost' ) ;
28+ return ;
29+ }
30+
2431 try {
2532 mixpanel . init ( MIXPANEL_TOKEN , {
2633 track_pageview : false ,
@@ -37,6 +44,7 @@ const initMixPanel = () => {
3744} ;
3845
3946const ensureInit = ( ) => {
47+ if ( isLocalhost ) return ;
4048 if ( ! isInitialized ) {
4149 console . warn ( 'Mixpanel not initialized. Initializing now.' ) ;
4250 initMixPanel ( ) ;
@@ -57,6 +65,7 @@ const createUserProperties = (user?: UserModel | null) => {
5765}
5866
5967export const trackEvent = ( event_name : string , properties ?: Dict , user ?: UserModel | null ) => {
68+ if ( isLocalhost ) return ;
6069 try {
6170 ensureInit ( ) ;
6271 const eventProperties = {
@@ -70,6 +79,7 @@ export const trackEvent = (event_name: string, properties?: Dict, user?: UserMod
7079} ;
7180
7281export const trackPageView = ( url : string , user : UserModel | null ) => {
82+ if ( isLocalhost ) return ;
7383 try {
7484 ensureInit ( ) ;
7585 const properties = {
@@ -83,6 +93,7 @@ export const trackPageView = (url: string, user: UserModel | null) => {
8393} ;
8494
8595export const trackClicks = ( event : MouseEvent , user : UserModel | null ) => {
96+ if ( isLocalhost ) return ;
8697 const target = event . target as HTMLElement ;
8798
8899 // check for anchor tags
0 commit comments