-
Notifications
You must be signed in to change notification settings - Fork 2
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
afb0359
commit 641c3ff
Showing
9 changed files
with
110 additions
and
6 deletions.
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
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
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
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
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,8 @@ | ||
const categories = { | ||
user: { | ||
guest: "Guest", | ||
signin: "Signed In User", | ||
}, | ||
}; | ||
|
||
export default categories; |
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,40 @@ | ||
import { event } from "nextjs-google-analytics"; | ||
import categories from "./categories"; | ||
import { useWalletStore } from "src/store"; | ||
import { useCallback } from "react"; | ||
|
||
type CreateEventProps = { | ||
category: string; | ||
action: string; | ||
userId?: string; | ||
}; | ||
|
||
const sendGaEvent = ({ action, category, userId }: CreateEventProps) => { | ||
event(action, { category, userId }); | ||
}; | ||
|
||
export const sendGuestGaEvent = (action: string) => | ||
sendGaEvent({ | ||
category: categories.user.guest, | ||
action, | ||
}); | ||
|
||
export const sendSignedInGaEvent = (action: string, address?: string) => | ||
sendGaEvent({ | ||
category: categories.user.signin, | ||
action, | ||
userId: address, | ||
}); | ||
|
||
export const useSendGaUserEvent = () => { | ||
const { address } = useWalletStore(state => ({ | ||
address: state.account?.address, | ||
})); | ||
const memoizedSignInGaEvent = useCallback( | ||
(action: string) => sendSignedInGaEvent(action, address), | ||
[address], | ||
); | ||
const sendGAEvent = address ? memoizedSignInGaEvent : sendGuestGaEvent; | ||
|
||
return sendGAEvent; | ||
}; |