Skip to content

Commit

Permalink
add ga events
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Oct 11, 2023
1 parent e86c151 commit 28ade2f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/analytics/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ export const serviceModalEvent = {
opened: ({ serviceId, serviceName, orgSlug }: ServiceModalOpenedAction) =>
event('select_content', { content_type: 'orgService', content_id: serviceId, serviceName, orgSlug }),
}

export const donateEvent = {
click: () => event('select_content', { content_type: 'donation_button' }),
}
export const userEvent = {
signup: (userType?: string) => event('sign_up', { userType }),
login: () => event('login'),
}
2 changes: 2 additions & 0 deletions packages/ui/components/core/Donate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Script from 'next/script'
import { useTranslation } from 'next-i18next'
import { type ReactElement, useEffect, useState } from 'react'

import { donateEvent } from '@weareinreach/analytics/events'
import { Button } from '~ui/components/core/Button'
import { Link } from '~ui/components/core/Link'
import { useCustomVariant } from '~ui/hooks/useCustomVariant'
Expand Down Expand Up @@ -52,6 +53,7 @@ export const DonateModal = ({ children }: DonateModalProps) => {
const buttonPosition = isMobile ? { bottom: rem(100), right: rem(12) } : { bottom: rem(40), right: rem(40) }

const buttonHandler = () => {
donateEvent.click()
if (isMobile) {
if (!showEmoji || opened) {
handler.close()
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/modals/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/no-unescaped-entities */
import {
Box,
type ButtonProps,
Expand All @@ -19,6 +18,7 @@ import { type Route } from 'nextjs-routes'
import { forwardRef, useState } from 'react'
import { z } from 'zod'

import { userEvent } from '@weareinreach/analytics/events'
import { Button } from '~ui/components/core/Button'
import { Link } from '~ui/components/core/Link'
import { useCustomVariant, useScreenSize, useShake } from '~ui/hooks'
Expand Down Expand Up @@ -66,6 +66,7 @@ export const LoginBody = forwardRef<HTMLDivElement, LoginBodyProps>(
}
}
if (result?.ok) {
userEvent.login()
if (modalHandler) {
modalHandler.close()
} else if (callbackUrl) {
Expand All @@ -92,7 +93,6 @@ export const LoginBody = forwardRef<HTMLDivElement, LoginBodyProps>(
{...form.getInputProps('password')}
/>
<Button
// eslint-disable-next-line @typescript-eslint/return-await
onClick={async () => await loginHandle(form.values.email, form.values.password)}
variant='primary-icon'
fullWidth
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/modals/SignUp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Trans, useTranslation } from 'next-i18next'
import { forwardRef, useEffect, useMemo, useRef, useState } from 'react'
import { type LiteralUnion } from 'type-fest'

import { userEvent } from '@weareinreach/analytics/events'
import { type ModalTitleBreadcrumb } from '~ui/components/core/Breadcrumb'
import { Button } from '~ui/components/core/Button'
import { Link } from '~ui/components/core/Link'
Expand Down Expand Up @@ -126,7 +127,8 @@ export const SignUpModalBody = forwardRef<HTMLButtonElement, SignUpModalBodyProp

const variants = useCustomVariant()
const signUpAction = api.user.create.useMutation({
onSuccess: () => {
onSuccess: (_data, variables) => {
userEvent.signup(variables.userType)
setSuccessMessage(true)
},
onError: (error) => {
Expand Down

0 comments on commit 28ade2f

Please sign in to comment.