summaryrefslogtreecommitdiff
path: root/src-migrate/hooks/useUtmSource.ts
blob: a72fae369a08137e48e0831071cfd858d2ad55bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import { UTM_SOURCE } from '~/constants/utm-source';

const useUtmSource = () => {
  const router = useRouter();
  const [source, setSource] = useState<string>();

  useEffect(() => {
    console.log(router.pathname);
    
    if (router.pathname) {
      setSource(UTM_SOURCE[router.pathname as keyof typeof UTM_SOURCE]);
    }
  }, [router.pathname]);

  return source;
};

export default useUtmSource;