Skip to content

Commit

Permalink
Addon: Added google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Sep 7, 2018
1 parent b2b7359 commit 1e5b562
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
25 changes: 25 additions & 0 deletions addons/google-analytics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Storybook Addon Google Analytics

Storybook Addon Google Analytics can be used to support google analytics in [Storybook](https://storybook.js.org).

[Framework Support](https://github.com/storybooks/storybook/blob/master/ADDONS_SUPPORT.md)

## Getting Started

Install:

```sh
npm i -D @storybook/addon-google-analytics
```

Then, add following content to `.storybook/addons.js`

```js
import '@storybook/addon-google-analytics/register';
```

Then, set an environment variable

```
STORYBOOK_GA_ID = UA-000000-01
```
28 changes: 28 additions & 0 deletions addons/google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@storybook/addon-google-analytics",
"version": "4.0.0-alpha.20",
"description": "Storybook addon for google analytics",
"keywords": [
"addon",
"storybook"
],
"homepage": "https://github.com/storybooks/storybook/tree/master/addons/google-analytics",
"bugs": {
"url": "https://github.com/storybooks/storybook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybooks/storybook.git"
},
"license": "MIT",
"main": "dist/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "4.0.0-alpha.20",
"global": "^4.3.2",
"react-ga": "^2.5.3"
}
}
1 change: 1 addition & 0 deletions addons/google-analytics/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
17 changes: 17 additions & 0 deletions addons/google-analytics/src/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import addons from '@storybook/addons';
import global from 'global';
import ReactGA from 'react-ga';

addons.register('storybook/google-analytics', api => {
ReactGA.initialize(global.STORYBOOK_GA_ID);

api.onStory((kind, story) => {
let path = global.window.location.pathname;

if (path === '/') {
path = '';
}

ReactGA.pageview(`${path}/${kind}/${story}`);
});
});
22 changes: 22 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14411,6 +14411,13 @@ react-fuzzy@^0.5.2:
fuse.js "^3.0.1"
prop-types "^15.5.9"

react-ga@^2.5.3:
version "2.5.3"
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-2.5.3.tgz#0f447c73664c069a5fc341f6f431262e3d4c23c4"
optionalDependencies:
prop-types "^15.6.0"
react "^15.6.2 || ^16.0"

react-inspector@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/react-inspector/-/react-inspector-2.3.0.tgz#fc9c1d38ab687fc0d190dcaf133ae40158968fc8"
Expand Down Expand Up @@ -14620,6 +14627,15 @@ react-transition-group@^2.0.0:
prop-types "^15.6.2"
react-lifecycles-compat "^3.0.4"

"react@^15.6.2 || ^16.0":
version "16.5.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.5.0.tgz#f2c1e754bf9751a549d9c6d9aca41905beb56575"
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
schedule "^0.3.0"

react@^16.4.2:
version "16.4.2"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.2.tgz#2cd90154e3a9d9dd8da2991149fdca3c260e129f"
Expand Down Expand Up @@ -15836,6 +15852,12 @@ sax@~1.1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.1.6.tgz#5d616be8a5e607d54e114afae55b7eaf2fcc3240"

schedule@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/schedule/-/schedule-0.3.0.tgz#1be2ab2fc2e768536269ce7326efb478d6c045e8"
dependencies:
object-assign "^4.1.1"

schema-utils@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.3.0.tgz#f5877222ce3e931edae039f17eb3716e7137f8cf"
Expand Down

0 comments on commit 1e5b562

Please sign in to comment.