diff --git a/CHANGELOG.md b/CHANGELOG.md index 713bc46..89e376d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## Added + +- `google analytics` pageview tracking on `SideBar` + ## [1.0.2] - 2019-09-16 ### Changed - Message `docs/latest-features`. diff --git a/react/components/SideBar.tsx b/react/components/SideBar.tsx index 2e9719c..4949aec 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('UA-150301985-1') + } + pageview(window.location.pathname + window.location.search) +} + const SideBar: FC = () => { const appName = 'vtex.io-documentation@0.x' const { content } = useSideBarContentState() + useEffect(() => pageView()) return (