From 315a361f2133652c73ae59be4a54eb9cb42860a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Gris?= Date: Thu, 17 Oct 2019 14:09:41 -0300 Subject: [PATCH 1/3] Add page view google analytics tracking. TODO: fix tracking ID --- react/components/SideBar.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/react/components/SideBar.tsx b/react/components/SideBar.tsx index 2e9719c..a394a10 100644 --- a/react/components/SideBar.tsx +++ b/react/components/SideBar.tsx @@ -1,8 +1,8 @@ -import React, { ReactElement, FC } from 'react' +import React, { ReactElement, FC, useEffect } from 'react' import { FormattedMessage } from 'react-intl' import { Drawer } from 'vtex.store-drawer' import { Link } from 'vtex.render-runtime' - +import { initialize, pageview, ga } from 'react-ga' import SideBarItem from './SideBarItem' import { formatLink } from '../utils' import { useSideBarContentState } from './SideBarContext' @@ -15,9 +15,17 @@ interface Chapter { articles: [] | Chapter[] } +function pageView() { + if (typeof ga() === 'undefined') { + initialize('1') + } + pageview(window.location.pathname + window.location.search) +} + const SideBar: FC = () => { const appName = 'vtex.io-documentation@0.x' const { content } = useSideBarContentState() + useEffect(() => pageView()) return (