mirror of
https://github.com/betagouv/mon-entreprise
synced 2025-02-10 13:55:03 +00:00
refactor: création et utilisation de useTracking
This commit is contained in:
parent
556193e861
commit
9b0df7b1c2
6 changed files with 17 additions and 14 deletions
|
@ -4,6 +4,10 @@ import { ATTracker } from './Tracker'
|
|||
|
||||
export const TrackingContext = createContext<ATTracker | null>(null)
|
||||
|
||||
export function useTracking(): ATTracker | null {
|
||||
return useContext(TrackingContext)
|
||||
}
|
||||
|
||||
// From https://github.com/nclsmitchell/at-internet
|
||||
export function toAtString(string: string): string {
|
||||
string = string.replace(/ /g, '_').toLowerCase()
|
||||
|
@ -78,7 +82,7 @@ export function TrackPage({
|
|||
children?: React.ReactNode
|
||||
} & Chapters) {
|
||||
const { chapter1, chapter2, chapter3 } = useChapters(chapters)
|
||||
const tag = useContext(TrackingContext)
|
||||
const tag = useTracking()
|
||||
useEffect(() => {
|
||||
tag?.sendEvent(
|
||||
'page.display',
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { useCallback, useContext, useState } from 'react'
|
||||
import { useCallback, useState } from 'react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
|
||||
import { TrackingContext } from '@/components/ATInternetTracking'
|
||||
import { useTracking } from '@/components/ATInternetTracking'
|
||||
import { Popover } from '@/design-system'
|
||||
import { Button } from '@/design-system/buttons'
|
||||
import { Emoji } from '@/design-system/emoji'
|
||||
|
@ -53,7 +53,7 @@ export function Feedback({
|
|||
const [isNotSatisfied, setIsNotSatisfied] = useState(false)
|
||||
const { t } = useTranslation()
|
||||
const url = useLocation().pathname
|
||||
const tag = useContext(TrackingContext)
|
||||
const tag = useTracking()
|
||||
|
||||
const { absoluteSitePaths } = useSitePaths()
|
||||
const currentPath = useLocation().pathname
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { useContext, useEffect, useRef, useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
|
||||
import { Button } from '@/design-system/buttons'
|
||||
|
@ -8,13 +8,13 @@ import { Strong } from '@/design-system/typography'
|
|||
import { H3 } from '@/design-system/typography/heading'
|
||||
import { Body, Intro, SmallBody } from '@/design-system/typography/paragraphs'
|
||||
|
||||
import { TrackingContext } from '../ATInternetTracking'
|
||||
import { useTracking } from '../ATInternetTracking'
|
||||
|
||||
export function ShareSimulationPopup({ url }: { url: string }) {
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const { t } = useTranslation()
|
||||
const [linkCopied, setLinkCopied] = useState(false)
|
||||
const tracker = useContext(TrackingContext)
|
||||
const tracker = useTracking()
|
||||
|
||||
const selectInput = () => {
|
||||
inputRef.current?.select()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { useContext } from 'react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { styled } from 'styled-components'
|
||||
|
||||
|
@ -8,7 +7,7 @@ import { Emoji } from '@/design-system/emoji'
|
|||
import { Grid, Spacing } from '@/design-system/layout'
|
||||
import { useUrl } from '@/hooks/useUrl'
|
||||
|
||||
import { TrackingContext } from '../ATInternetTracking'
|
||||
import { useTracking } from '../ATInternetTracking'
|
||||
import { ConseillersEntreprisesButton } from '../ConseillersEntreprisesButton'
|
||||
import { ShareSimulationPopup } from './ShareSimulationPopup'
|
||||
|
||||
|
@ -33,7 +32,7 @@ export default function ShareOrSaveSimulationBanner({
|
|||
customSimulationbutton?: CustomSimulationButton
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const tracker = useContext(TrackingContext)
|
||||
const tracker = useTracking()
|
||||
const shareAPIAvailable = !!window?.navigator?.share
|
||||
const url = useUrl()
|
||||
const startSharing = async () => {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { Li, Ul } from '@/design-system/typography/list'
|
|||
import { Body, SmallBody } from '@/design-system/typography/paragraphs'
|
||||
|
||||
import * as safeLocalStorage from '../../../storage/safeLocalStorage'
|
||||
import { TrackingContext, TrackPage } from '../../ATInternetTracking'
|
||||
import { TrackPage, useTracking } from '../../ATInternetTracking'
|
||||
|
||||
const StyledTable = styled.table`
|
||||
&,
|
||||
|
@ -35,7 +35,7 @@ export default function PrivacyPolicy({
|
|||
label?: string
|
||||
noUnderline?: boolean
|
||||
}) {
|
||||
const tracker = useContext(TrackingContext)
|
||||
const tracker = useTracking()
|
||||
const [valueChanged, setValueChanged] = useState(false)
|
||||
const { t } = useTranslation()
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { lazy, Suspense, useContext, useRef, useState } from 'react'
|
|||
import SignaturePad from 'react-signature-pad-wrapper'
|
||||
import { useTheme } from 'styled-components'
|
||||
|
||||
import { TrackingContext, TrackPage } from '@/components/ATInternetTracking'
|
||||
import { TrackPage, useTracking } from '@/components/ATInternetTracking'
|
||||
import { Condition } from '@/components/EngineValue/Condition'
|
||||
import { EngineContext, EngineProvider } from '@/components/utils/EngineContext'
|
||||
import { Message, PopoverWithTrigger } from '@/design-system'
|
||||
|
@ -32,7 +32,7 @@ export default function EndBlock({ fields, missingValues }: EndBlockProps) {
|
|||
const [place, setPlace] = useState<string>()
|
||||
const engine = useContext(EngineContext)
|
||||
const signatureRef = useRef<SignaturePad | null>(null)
|
||||
const tracker = useContext(TrackingContext)
|
||||
const tracker = useTracking()
|
||||
const { colors } = useTheme()
|
||||
if (missingValues.length) {
|
||||
return (
|
||||
|
|
Loading…
Add table
Reference in a new issue