Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Commit

Permalink
Upload code
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed Jun 22, 2018
1 parent 609a518 commit 3452052
Show file tree
Hide file tree
Showing 8 changed files with 1,739 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"env",
"minify"
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ typings/

# next.js build output
.next

dist
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src
.babelrc
!dist
yarn.lock
32 changes: 31 additions & 1 deletion README.md
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).
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./dist/index");
36 changes: 36 additions & 0 deletions package.json
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"
}
}
15 changes: 15 additions & 0 deletions src/index.js
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);
};
Loading

0 comments on commit 3452052

Please sign in to comment.