-
Notifications
You must be signed in to change notification settings - Fork 180
/
analytics.examples.js
52 lines (40 loc) · 1.21 KB
/
analytics.examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {action} from '@storybook/addon-actions';
import linkStyles from '../link/link.css';
import analytics from './analytics';
import AnalyticsCustomPlugin from './analytics__custom-plugin';
export default {
title: 'Components|Analytics',
parameters: {
notes:
'Provides a façade to Google Analytics and other web analytics services through a system of plugins.',
hermione: {skip: true}
}
};
export const analyticsStory = () => {
const node = document.createElement('div');
node.innerHTML = `
<div>
<p>Click the link below and check the console output:</p>
<div>
<a href id="click-me" class="${linkStyles.link}">
Track click event
</a>
</div>
</div>
`;
const FLUSH_INTERVAL = 100;
const customPlugin = new AnalyticsCustomPlugin(
events => action('analytics')('Custom plugin receives:', events[0].category, events[0].action),
false,
FLUSH_INTERVAL
);
analytics.config([customPlugin]);
node.querySelector('#click-me').addEventListener('click', event => {
analytics.trackEvent('test-category', 'test-action');
event.preventDefault();
});
return node;
};
analyticsStory.story = {
name: 'analytics'
};