Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 319a214

Browse files
committed
Merge master into v3-beta.
2 parents 25f967e + a33a01f commit 319a214

File tree

8 files changed

+105
-3
lines changed

8 files changed

+105
-3
lines changed

examples/with-react-ga/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-react-ga)
2+
3+
# React-GA example
4+
5+
## How to use
6+
7+
Download the example [or clone the repo](https://github.com/zeit/next.js):
8+
9+
```bash
10+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-react-ga
11+
cd with-react-ga
12+
```
13+
14+
Install it and run:
15+
16+
```bash
17+
npm install
18+
npm run dev
19+
```
20+
21+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
22+
23+
```bash
24+
now
25+
```
26+
27+
## The idea behind the example
28+
29+
This example shows the most basic way to use [react-ga](https://github.com/react-ga/react-ga) using `<Layout/>` component with NextJs. You can also use an HOC instead of `<Layout/>` component. Modify `Tracking ID` in `utils/analytics.js` file for testing this example.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
import { initGA, logPageView } from '../utils/analytics'
3+
4+
export default class Layout extends React.Component {
5+
componentDidMount () {
6+
if (!window.GA_INITIALIZED) {
7+
initGA()
8+
window.GA_INITIALIZED = true
9+
}
10+
logPageView()
11+
}
12+
render () {
13+
return (
14+
<div>
15+
{this.props.children}
16+
</div>
17+
)
18+
}
19+
}

examples/with-react-ga/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "hello-world",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "next",
6+
"build": "next build",
7+
"start": "next start"
8+
},
9+
"dependencies": {
10+
"next": "*",
11+
"react": "^15.4.2",
12+
"react-dom": "^15.4.2",
13+
"react-ga": "2.2.0"
14+
},
15+
"author": "",
16+
"license": "ISC"
17+
}

examples/with-react-ga/pages/about.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Layout from '../components/Layout'
2+
3+
export default () => (
4+
<Layout>
5+
<div>About us</div>
6+
</Layout>
7+
)

examples/with-react-ga/pages/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Link from 'next/link'
2+
import Layout from '../components/Layout'
3+
4+
export default () => (
5+
<Layout><div>Hello World. <Link href='/about'><a>About</a></Link></div></Layout>
6+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ReactGA from 'react-ga'
2+
3+
export const initGA = () => {
4+
console.log('GA init')
5+
ReactGA.initialize('UA-xxxxxxxxx-1')
6+
}
7+
8+
export const logPageView = () => {
9+
console.log(`Logging pageview for ${window.location.pathname}`)
10+
ReactGA.set({ page: window.location.pathname })
11+
ReactGA.pageview(window.location.pathname)
12+
}
13+
14+
export const logEvent = (category = '', action = '') => {
15+
if (category && action) {
16+
ReactGA.event({ category, action })
17+
}
18+
}
19+
20+
export const logException = (description = '', fatal = false) => {
21+
if (description) {
22+
ReactGA.exception({ description, fatal })
23+
}
24+
}

examples/with-socket.io/pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class HomePage extends Component {
2222

2323
// connect to WS server and listen event
2424
componentDidMount () {
25-
this.socket = io('http://localhost:3000/')
25+
this.socket = io()
2626
this.socket.on('message', this.handleMessage)
2727
}
2828

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4330,11 +4330,11 @@ public-encrypt@^4.0.0:
43304330
parse-asn1 "^5.0.0"
43314331
randombytes "^2.0.1"
43324332

4333-
4333+
[email protected], punycode@^1.2.4:
43344334
version "1.3.2"
43354335
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d"
43364336

4337-
punycode@^1.2.4, punycode@^1.4.1:
4337+
punycode@^1.4.1:
43384338
version "1.4.1"
43394339
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
43404340

0 commit comments

Comments
 (0)