Skip to content

Commit aa5b51d

Browse files
author
João Marcos Gris
authored
Merge pull request #38 from vtex-apps/google-analytics
Track Page Views in Google Analytics
2 parents d01399a + 6d45a12 commit aa5b51d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## Added
11+
12+
- `google analytics` pageview tracking on `SideBar`
13+
1014
## [1.0.2] - 2019-09-16
1115
### Changed
1216
- Message `docs/latest-features`.

react/components/SideBar.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { ReactElement, FC } from 'react'
1+
import React, { ReactElement, FC, useEffect } from 'react'
22
import { FormattedMessage } from 'react-intl'
33
import { Drawer } from 'vtex.store-drawer'
44
import { Link } from 'vtex.render-runtime'
5-
5+
import { initialize, pageview, ga } from 'react-ga'
66
import SideBarItem from './SideBarItem'
77
import { formatLink } from '../utils'
88
import { useSideBarContentState } from './SideBarContext'
@@ -15,9 +15,17 @@ interface Chapter {
1515
articles: [] | Chapter[]
1616
}
1717

18+
function pageView() {
19+
if (typeof ga() === 'undefined') {
20+
initialize('UA-150301985-1')
21+
}
22+
pageview(window.location.pathname + window.location.search)
23+
}
24+
1825
const SideBar: FC = () => {
1926
const appName = '[email protected]'
2027
const { content } = useSideBarContentState()
28+
useEffect(() => pageView())
2129

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

0 commit comments

Comments
 (0)