You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gtag.ts 557B

1234567891011121314151617181920212223242526
  1. export const GA_TRACKING_ID = process.env.GA_MEASUREMENT_ID
  2. type GTagEvent = {
  3. action: string
  4. category: string
  5. label: string
  6. value: number
  7. }
  8. export const pageview = (url: URL): void => {
  9. if ('gtag' in window) {
  10. ;(window as any)?.gtag('config', GA_TRACKING_ID, {
  11. page_path: url,
  12. })
  13. }
  14. }
  15. export const event = ({ action, category, label, value }: GTagEvent): void => {
  16. if ('gtag' in window) {
  17. ;(window as any)?.gtag('event', action, {
  18. event_category: category,
  19. event_label: label,
  20. value: value,
  21. })
  22. }
  23. }