diff --git a/apps/gamification/utils/customGTMEventTracking.ts b/apps/gamification/utils/customGTMEventTracking.ts new file mode 100644 index 0000000000000..85d63a73381b2 --- /dev/null +++ b/apps/gamification/utils/customGTMEventTracking.ts @@ -0,0 +1,37 @@ +export enum GTMEvent { + StartQuest = 'startQuest', +} + +export enum GTMCategory { + Quest = 'Quest', +} + +export enum GTMAction { + ClickStartQuestButton = 'Click Start Quest Button', +} + +interface CustomGTMDataLayer { + event: GTMEvent + category?: GTMCategory + action?: GTMAction + label?: string +} + +type WindowWithDataLayer = Window & { + dataLayer: CustomGTMDataLayer[] | undefined +} + +declare const window: WindowWithDataLayer + +export const customGTMEvent: WindowWithDataLayer['dataLayer'] = + typeof window !== 'undefined' ? window?.dataLayer : undefined + +export const logGTMClickStartQuestEvent = (label?: string) => { + console.info('---StartQuest---') + window?.dataLayer?.push({ + event: GTMEvent.StartQuest, + action: GTMAction.ClickStartQuestButton, + category: GTMCategory.Quest, + label, + }) +} diff --git a/apps/gamification/views/Quest/components/Tasks/index.tsx b/apps/gamification/views/Quest/components/Tasks/index.tsx index 36d1ad048490c..d8bc087b7c649 100644 --- a/apps/gamification/views/Quest/components/Tasks/index.tsx +++ b/apps/gamification/views/Quest/components/Tasks/index.tsx @@ -11,6 +11,7 @@ import { MakeProfileModal } from 'views/Quest/components/MakeProfileModal' import { Task } from 'views/Quest/components/Tasks/Task' import { VerifyTaskStatus } from 'views/Quest/hooks/useVerifyTaskStatus' import { useAccount } from 'wagmi' +import { logGTMClickStartQuestEvent } from 'utils/customGTMEventTracking' const OverlapContainer = styled(Box)` position: absolute; @@ -104,6 +105,7 @@ export const Tasks: React.FC = ({ } else if (!hasProfile) { onPressMakeProfileModal() } else { + logGTMClickStartQuestEvent(`${account}-${questId}`) handleLinkUserToQuest() } }