-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
5 changed files
with
93 additions
and
0 deletions.
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,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 | ||
``` |
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,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" | ||
} | ||
} |
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 @@ | ||
export default {}; |
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,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}`); | ||
}); | ||
}); |
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