This repository has been archived by the owner on Jul 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,739 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"env", | ||
"minify" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,5 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
|
||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
src | ||
.babelrc | ||
!dist | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# next-analytics | ||
Next.js HOC to integrate GAnalytics and FB Pixel | ||
|
||
Next.js HOC to integrate analytics tools (GA and FBQ). | ||
|
||
## Usage | ||
|
||
Install it | ||
|
||
```bash | ||
yarn add next-analytics | ||
``` | ||
|
||
Import it inside your `pages/_app.js`; | ||
|
||
```js | ||
import withAnalytics from "next-analytics"; | ||
``` | ||
|
||
Wrap your [custom App container](https://nextjs.org/docs#custom-%3Capp%3E) with it | ||
|
||
```js | ||
// pass an object with your Google Analytics and/or Facebook Pixel code as first argument | ||
export default withAnalytics({ ga: "UA-xxxxxxxxx-1", fbq: "139xxxxxxxxx3" })(MyApp); | ||
``` | ||
|
||
That's it, now when the user access a page it will log a pageview to Google Analytics and/or Facebook Pixel, each page change after that will also trigger a pageview on GA and/or FBQ. | ||
|
||
> **Note**: This module only applies the HOC next-ga or next-fbq if the code is sent when instancing | ||
## Credits | ||
|
||
Thanks to [@joecohens](https://github.com/joecohens) for creating [next-fbq](https://github.com/joecohens/next-fbq). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("./dist/index"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "next-analytics", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"repository": "https://github.com/sergiodxa/next-analytics.git", | ||
"author": "Sergio Xalambrí <[email protected]>", | ||
"license": "MIT", | ||
"keywords": [ | ||
"nextjs", | ||
"react", | ||
"analytics", | ||
"ga", | ||
"google analytics", | ||
"fbq", | ||
"facebook pixel", | ||
"hoc", | ||
"high order component" | ||
], | ||
"scripts": { | ||
"build": "babel src -d dist", | ||
"prepublish": "npm run build" | ||
}, | ||
"dependencies": { | ||
"next-fbq": "^1.0.0", | ||
"next-ga": "^1.0.3" | ||
}, | ||
"peerDependencies": { | ||
"next": "^6.0.0", | ||
"react": "^16.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-minify": "^0.4.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import withGA from "next-ga"; | ||
import withFBQ from "next-fbq"; | ||
|
||
export default ({ ga, fbq } = {}) => Page => { | ||
const hocs = []; | ||
|
||
// add withGA (passing GA code) to list of HOCs | ||
if (ga) hocs.push(withGA(ga)); | ||
|
||
// add withFBQ (passing FBQ code) to list of HOCs | ||
if (fbq) hocs.push(withFBQ(fbq)); | ||
|
||
// apply each HOC to the Page | ||
return hocs.reduce((WrappedPage, hoc) => hoc(WrappedPage), Page); | ||
}; |
Oops, something went wrong.