@atlaskit/analytics-next 11.1.4 → 11.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/AnalyticsReactContext/package.json +15 -0
  2. package/CHANGELOG.md +21 -0
  3. package/afm-cc/tsconfig.json +0 -2
  4. package/afm-products/tsconfig.json +0 -2
  5. package/cleanProps/package.json +15 -0
  6. package/dist/cjs/components/AnalyticsReactContext.js +13 -0
  7. package/dist/cjs/events/UIAnalyticsEvent.js +11 -1
  8. package/dist/cjs/index.js +2 -2
  9. package/dist/cjs/utils/isModernContextEnabledEnv.js +2 -1
  10. package/dist/es2019/components/AnalyticsReactContext.js +1 -0
  11. package/dist/es2019/events/UIAnalyticsEvent.js +13 -1
  12. package/dist/es2019/index.js +1 -1
  13. package/dist/es2019/utils/isModernContextEnabledEnv.js +2 -1
  14. package/dist/esm/components/AnalyticsReactContext.js +1 -0
  15. package/dist/esm/events/UIAnalyticsEvent.js +11 -1
  16. package/dist/esm/index.js +1 -1
  17. package/dist/esm/utils/isModernContextEnabledEnv.js +2 -1
  18. package/dist/types/components/AnalyticsContext/index.d.ts +1 -1
  19. package/dist/types/components/AnalyticsContext/types.d.ts +1 -1
  20. package/dist/types/components/AnalyticsListener/LegacyAnalyticsListener.d.ts +1 -1
  21. package/dist/types/components/AnalyticsListener/index.d.ts +1 -1
  22. package/dist/types/components/AnalyticsListener/types.d.ts +1 -1
  23. package/dist/types/components/AnalyticsReactContext.d.ts +2 -0
  24. package/dist/types/hocs/withAnalyticsEvents.d.ts +1 -1
  25. package/dist/types/hooks/useAnalyticsEvents.d.ts +1 -1
  26. package/dist/types/hooks/usePatchedProps.d.ts +1 -1
  27. package/dist/types/index.d.ts +2 -2
  28. package/dist/types/types.d.ts +1 -1
  29. package/dist/types/utils/createAndFireEvent.d.ts +2 -2
  30. package/dist/types/utils/isModernContextEnabledEnv.d.ts +2 -2
  31. package/dist/types-ts4.5/components/AnalyticsContext/index.d.ts +1 -1
  32. package/dist/types-ts4.5/components/AnalyticsContext/types.d.ts +1 -1
  33. package/dist/types-ts4.5/components/AnalyticsListener/LegacyAnalyticsListener.d.ts +1 -1
  34. package/dist/types-ts4.5/components/AnalyticsListener/index.d.ts +1 -1
  35. package/dist/types-ts4.5/components/AnalyticsListener/types.d.ts +1 -1
  36. package/dist/types-ts4.5/components/AnalyticsReactContext.d.ts +2 -0
  37. package/dist/types-ts4.5/hocs/withAnalyticsEvents.d.ts +1 -1
  38. package/dist/types-ts4.5/hooks/useAnalyticsEvents.d.ts +1 -1
  39. package/dist/types-ts4.5/hooks/usePatchedProps.d.ts +1 -1
  40. package/dist/types-ts4.5/index.d.ts +2 -2
  41. package/dist/types-ts4.5/types.d.ts +1 -1
  42. package/dist/types-ts4.5/utils/createAndFireEvent.d.ts +2 -2
  43. package/dist/types-ts4.5/utils/isModernContextEnabledEnv.d.ts +2 -2
  44. package/docs/0-intro.tsx +68 -37
  45. package/docs/10-concepts.tsx +138 -112
  46. package/docs/20-usage-with-presentational-components.tsx +177 -198
  47. package/docs/30-usage-for-container-components.tsx +69 -53
  48. package/docs/40-listeners.tsx +17 -14
  49. package/docs/50-error-boundary.tsx +28 -22
  50. package/docs/60-events.tsx +27 -19
  51. package/docs/70-advanced-usage.tsx +182 -179
  52. package/docs/80-upgrade-guide.tsx +182 -100
  53. package/docs/DocBlocks.tsx +106 -0
  54. package/package.json +2 -2
  55. package/tsconfig.json +1 -2
  56. package/usePlatformLeafSyntheticEventHandler/package.json +15 -0
  57. package/afm-jira/tsconfig.json +0 -33
@@ -1,122 +1,148 @@
1
- import { code, md } from '@atlaskit/docs';
1
+ /* eslint-disable @atlaskit/design-system/use-primitives-text, @atlaskit/design-system/use-heading, @atlaskit/design-system/no-html-anchor -- Legacy analytics-next docs intentionally use plain HTML prose and links instead of ADS docs primitives. */
2
+ import React from 'react';
2
3
 
3
- const _default_1: any = md`
4
- There are 3 abstract layers as part of \`@atlaskit/analytics-next\`:
4
+ import { CodeBlock } from './DocBlocks';
5
5
 
6
- - [Analytics Listeners](./listeners) (responsible for sending events over the network)
7
- - [Consumer Components](./usage-with-presentational-components) (target components that are desired to be tracked. They fire events that the listener consumes)
8
- - [Analytics Contexts](./usage-for-container-components) (provides contextual data to consumer components about the \"container\" they are embeded in. This data is added to the event fired by all consumer components that are its children.)
6
+ const exampleCode = `
7
+ // ---- CONSUMER COMPONENT LAYER ----
9
8
 
10
- ### React Context: !important;
11
-
12
- These layers communicate via React context. Historically this package has used [legacy React Context][legacy-context], but
13
- is now transitioning to use only the new [React Context API][modern-context]. This is to prepare for
14
- future versions of React in which legacy Context will be dropped, but also partially for performance reasons.
15
-
16
- To achieve dropping legacy context we are rolling the drop out in 2 phases:
17
-
18
- #### Phase I (version 7.1.0)
19
-
20
- Analytics consuming components receive only modern context. Listeners and the Context layer will provide both modern and legacy context by default.
21
-
22
- At their own risk, package consumers can opt in to no longer supply legacy context by using the environment variable
23
- ANALYTICS_NEXT_MODERN_CONTEXT=true.
24
-
25
- When doing so, any analytics consumers that rely on legacy context will not receive any, and events may be lost! This would happen when using old atlaskit packages that consume a version of @atlaskit/analytics-next before version 7.1.0.
26
-
27
- #### Phase II (future major)
28
-
29
- In a future release (TBA) we will remove all legacy context support and clean up the branching around ANALYTICS_NEXT_MODERN_CONTEXT.
30
- After this point, @atlaskit/analytics-next will not work with components that use a version prior to 7.1.0.
31
-
32
- ### Example
33
-
34
- ${code`
35
- // ---- CONSUMER COMPONENT LAYER ----
9
+ // We want to add tracking for the 'click' of this button
10
+ const TargetButton = ({ onClick }) => {
11
+ // this analytics event is given to the callback via the
12
+ // HOC wrapping of this component below
13
+ const handler = (clickEvent, analyticsEvent) => {
14
+ analyticsEvent.fire("myTargetChannel");
15
+ };
36
16
 
37
- // We want to add tracking for the 'click' of this button
38
- const TargetButton = ({ onClick }) => {
39
- // this analytics event is given to the callback via the
40
- // HOC wrapping of this component below
41
- const handler = (clickEvent, analyticsEvent) => {
42
- analyticsEvent.fire("myTargetChannel");
43
- };
17
+ return <button onClick={handler}>Track me</button>
18
+ }
44
19
 
45
- return <button onClick={handler}>Track me</button>
20
+ // Analytics can be baked into your target components
21
+ // in a number of ways, this is just one of many!
22
+ const AnalyticsWrappedButton = withAnalyticsEvent({
23
+ onClick: {
24
+ component: 'button',
25
+ action: 'clicked'
46
26
  }
47
-
48
- // Analytics can be baked into your target components
49
- // in a number of ways, this is just one of many!
50
- const AnalyticsWrappedButton = withAnalyticsEvent({
51
- onClick: {
52
- component: 'button',
27
+ })(TargetButton);
28
+
29
+ // ---- ANALYTICS CONTEXT LAYER ----
30
+
31
+ // Our target button is going to be used inside of a form
32
+ const FormContainer = ({ children }) => {
33
+ return (
34
+ <form>
35
+ {children}
36
+ </form>
37
+ );
38
+ }
39
+
40
+ // This wrapper gives the container a way of passing to its children
41
+ // components some context about where it is consumed.
42
+ // Again there are a few ways of doing this!
43
+ const AnalyticsWrappedForm = withAnayticsContext({
44
+ container: 'submissionForm',
45
+ page: '/invite-a-friend'
46
+ })(FormContainer);
47
+
48
+ // ---- ANALYTICS LISTENER LAYER ----
49
+
50
+ // This is our App's listener
51
+ // Note: It is possible to have multiple listeners, all listening
52
+ // on different channels, allowing for different handlers for different
53
+ // kind of events
54
+ const OurAnalyticsListener = ({ children }) => {
55
+ const onEvent = (event, channel) => {
56
+ // these components are agnostic to what you want to use
57
+ // to send events to the network
58
+ someClient.sendToNetwork(event);
59
+
60
+ expect(event.payload).toBe({
53
61
  action: 'clicked'
54
- }
55
- })(TargetButton);
56
-
57
- // ---- ANALYTICS CONTEXT LAYER ----
58
-
59
- // Our target button is going to be used inside of a form
60
- const FormContainer = ({ children }) => {
61
- return (
62
- <form>
63
- {children}
64
- </form>
65
- );
66
- }
67
-
68
- // This wrapper gives the container a way of passing to its children
69
- // components some context about where it is consumed.
70
- // Again there are a few ways of doing this!
71
- const AnalyticsWrappedForm = withAnayticsContext({
72
- container: 'submissionForm',
73
- page: '/invite-a-friend'
74
- })(FormContainer);
75
-
76
- // ---- ANALYTICS LISTENER LAYER ----
77
-
78
- // This is our App's listener
79
- // Note: It is possible to have multiple listeners, all listening
80
- // on different channels, allowing for different handlers for different
81
- // kind of events
82
- const OurAnalyticsListener = ({ children }) => {
83
- const onEvent = (event, channel) => {
84
- // these components are agnostic to what you want to use
85
- // to send events to the network
86
- someClient.sendToNetwork(event);
87
-
88
- expect(event.payload).toBe({
89
- action: 'clicked'
90
- component: 'button'
91
- });
92
-
93
- // an array of contexts (multiple context containers can be nested)
94
- expect(event.context).toBe([{
95
- container: 'submissionForm',
96
- page: '/invite-a-friend'
97
- });
98
- };
99
-
100
- return (
101
- <AnalyticsListener channel="myTargetChannel" onEvent={onEvent}>
102
- {children}
103
- </AnalyticsListener>
104
- )
105
- }
106
-
107
- // ---- ALL TOGETHER ----
108
-
109
- export const ExampleApp = () => {
110
- return (
111
- <OurAnalyticsListener> // Listener layer in this example
112
- <AnalyticsWrappedForm> // Context layer in this example
113
- <AnalyticsWrappedButton/> // Consumer component layer in this example
114
- </AnalyticsWrappedForm>
115
- </OurAnalyticsListener>);
62
+ component: 'button'
63
+ });
64
+
65
+ // an array of contexts (multiple context containers can be nested)
66
+ expect(event.context).toBe([{
67
+ container: 'submissionForm',
68
+ page: '/invite-a-friend'
69
+ });
116
70
  };
117
- `}
118
71
 
119
- [legacy-context]: https://reactjs.org/docs/legacy-context.html
120
- [modern-context]: https://reactjs.org/docs/context.html
72
+ return (
73
+ <AnalyticsListener channel="myTargetChannel" onEvent={onEvent}>
74
+ {children}
75
+ </AnalyticsListener>
76
+ )
77
+ }
78
+
79
+ // ---- ALL TOGETHER ----
80
+
81
+ export const ExampleApp = () => {
82
+ return (
83
+ <OurAnalyticsListener>
84
+ <AnalyticsWrappedForm>
85
+ <AnalyticsWrappedButton/>
86
+ </AnalyticsWrappedForm>
87
+ </OurAnalyticsListener>);
88
+ };
121
89
  `;
122
- export default _default_1;
90
+
91
+ export default function Concepts(): React.JSX.Element {
92
+ return (
93
+ <div>
94
+ <p>
95
+ There are 3 abstract layers as part of <code>@atlaskit/analytics-next</code>:
96
+ </p>
97
+ <ul>
98
+ <li>
99
+ <a href="./listeners">Analytics Listeners</a> (responsible for sending events over the
100
+ network)
101
+ </li>
102
+ <li>
103
+ <a href="./usage-with-presentational-components">Consumer Components</a> (target
104
+ components that are desired to be tracked. They fire events that the listener consumes)
105
+ </li>
106
+ <li>
107
+ <a href="./usage-for-container-components">Analytics Contexts</a> (provides contextual
108
+ data to consumer components about where it is embeded in the &quot;container&quot; they
109
+ are embeded in. This data is added to the event fired by all consumer components that are
110
+ its children.)
111
+ </li>
112
+ </ul>
113
+
114
+ <h3>React Context: !important;</h3>
115
+ <p>
116
+ These layers communicate via React context. Historically this package has used{' '}
117
+ <a href="https://reactjs.org/docs/legacy-context.html">legacy React Context</a>, but is now
118
+ transitioning to use only the new{' '}
119
+ <a href="https://reactjs.org/docs/context.html">React Context API</a>. This is to prepare
120
+ for future versions of React in which legacy Context will be dropped, but also partially for
121
+ performance reasons.
122
+ </p>
123
+ <p>To achieve dropping legacy context we are rolling the drop out in 2 phases:</p>
124
+ <h4>Phase I (version 7.1.0)</h4>
125
+ <p>
126
+ Analytics consuming components receive only modern context. Listeners and the Context layer
127
+ will provide both modern and legacy context by default.
128
+ </p>
129
+ <p>
130
+ At their own risk, package consumers can opt in to no longer supply legacy context by using
131
+ the environment variable ANALYTICS_NEXT_MODERN_CONTEXT=true.
132
+ </p>
133
+ <p>
134
+ When doing so, any analytics consumers that rely on legacy context will not receive any, and
135
+ events may be lost! This would happen when using old atlaskit packages that consume a
136
+ version of @atlaskit/analytics-next before version 7.1.0.
137
+ </p>
138
+ <h4>Phase II (future major)</h4>
139
+ <p>
140
+ In a future release (TBA) we will remove all legacy context support and clean up the
141
+ branching around ANALYTICS_NEXT_MODERN_CONTEXT. After this point, @atlaskit/analytics-next
142
+ will not work with components that use a version prior to 7.1.0.
143
+ </p>
144
+ <h3>Example</h3>
145
+ <CodeBlock code={exampleCode} />
146
+ </div>
147
+ );
148
+ }