Skip to content

Commit

Permalink
Merge pull request #38 from vtex-apps/google-analytics
Browse files Browse the repository at this point in the history
Track Page Views in Google Analytics
  • Loading branch information
João Marcos Gris authored Oct 23, 2019
2 parents d01399a + 6d45a12 commit aa5b51d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
12 changes: 10 additions & 2 deletions react/components/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 = '[email protected]'
const { content } = useSideBarContentState()
useEffect(() => pageView())

return (
<nav className="w-100 fixed static-l bg-base z-2 min-h-100-l br-l b--muted-3 flex-l flex-column">
Expand Down

0 comments on commit aa5b51d

Please sign in to comment.