Skip to content

Commit

Permalink
feat: Add ga in start quest (#10729)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR introduces Google Tag Manager (GTM) event tracking for starting
a quest in the application. It adds functionality to log a specific
event when a user initiates a quest, enhancing the tracking of user
interactions.

### Detailed summary
- Added `logGTMClickStartQuestEvent` function in
`utils/customGTMEventTracking.ts` to log quest start events.
- Introduced enums `GTMEvent`, `GTMCategory`, and `GTMAction` for
structured event tracking.
- Updated the `Tasks` component in
`apps/gamification/views/Quest/components/Tasks/index.tsx` to call
`logGTMClickStartQuestEvent` when a quest is started.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
memoyil authored Sep 24, 2024
1 parent b3777dc commit b123679
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions apps/gamification/utils/customGTMEventTracking.ts
Original file line number Diff line number Diff line change
@@ -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,
})
}
2 changes: 2 additions & 0 deletions apps/gamification/views/Quest/components/Tasks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,6 +105,7 @@ export const Tasks: React.FC<TasksProps> = ({
} else if (!hasProfile) {
onPressMakeProfileModal()
} else {
logGTMClickStartQuestEvent(`${account}-${questId}`)
handleLinkUserToQuest()
}
}
Expand Down

0 comments on commit b123679

Please sign in to comment.