Skip to content

Commit

Permalink
Allow passing custom settings using ReactGA.set()
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelig authored Jun 28, 2021
1 parent 1924635 commit 2009e91
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import ReactGA from 'react-ga';
addons.register('storybook/google-analytics', (api) => {
ReactGA.initialize(globalWindow.STORYBOOK_GA_ID, globalWindow.STORYBOOK_REACT_GA_OPTIONS);

if (window.STORYBOOK_GA_OPTIONS && 'set' in window.STORYBOOK_GA_OPTIONS) {
// Sets a single field and value pair or a group of field/value pairs on a tracker object.
// @see https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#set
ReactGA.set(window.STORYBOOK_GA_OPTIONS.set);
}

api.on(STORY_CHANGED, () => {
const { path } = api.getUrlState();
ReactGA.pageview(path);
Expand Down

0 comments on commit 2009e91

Please sign in to comment.