-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08f992b
commit e076ce6
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
enum MIXPANEL_EVENTS { | ||
"test" = "test", | ||
"subscribe" = "subscribe", | ||
"connectWallet" = "connectWallet", | ||
"purchaseTokens" = "purchaseTokens", | ||
"error" = "error", | ||
} | ||
|
||
type MixpanelEventType = keyof typeof MIXPANEL_EVENTS; | ||
|
||
export const trackEvent = (event_name: MixpanelEventType, props?: any) => { | ||
try { | ||
if ((window as any).mixpanel) { | ||
(window as any).mixpanel.track(event_name, props); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; | ||
|
||
export const trackPageview = (props?: any) => { | ||
try { | ||
if ((window as any).mixpanel) { | ||
(window as any).mixpanel.track_pageview(props); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; | ||
|
||
export const mixpanelIdentify = (id: string | number) => { | ||
try { | ||
if ((window as any).mixpanel) { | ||
(window as any).mixpanel.identify(id); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; | ||
|
||
export const mixpanelSetProfileProp = (name: string, value: any) => { | ||
try { | ||
if ((window as any).mixpanel) { | ||
(window as any).mixpanel.people.set({ [name]: value }); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
"use client"; | ||
|
||
import { ChakraProvider } from "@chakra-ui/react"; | ||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
import { trackPageview } from "./contacts/mixpanel"; | ||
import { theme } from "./theme"; | ||
|
||
export function Providers({ children }: { children: React.ReactNode }) { | ||
return <ChakraProvider theme={theme}>{children}</ChakraProvider>; | ||
} | ||
|
||
export const NavigationEvents = () => { | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
const currentUrl = useRef(""); | ||
|
||
useEffect(() => { | ||
const url = `${pathname}?${searchParams}`; | ||
if (currentUrl.current !== url) { | ||
currentUrl.current = url; | ||
// Mixpanel rounting events | ||
//Send track event when new pages is loaded | ||
trackPageview(); | ||
} | ||
}, [pathname, searchParams]); | ||
|
||
return null; | ||
}; |