@atlaskit/analytics-next 10.1.1 → 10.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 (56) hide show
  1. package/AnalyticsDecorator/package.json +15 -0
  2. package/AnalyticsDelegate/package.json +15 -0
  3. package/CHANGELOG.md +18 -0
  4. package/afm-cc/tsconfig.json +1 -2
  5. package/afm-jira/tsconfig.json +24 -24
  6. package/afm-post-office/tsconfig.json +24 -24
  7. package/dist/cjs/components/AnalyticsContext/LegacyAnalyticsContext.js +8 -11
  8. package/dist/cjs/components/AnalyticsContext/index.js +1 -1
  9. package/dist/cjs/components/AnalyticsDecorator/index.js +104 -0
  10. package/dist/cjs/components/AnalyticsDelegate/index.js +72 -0
  11. package/dist/cjs/components/AnalyticsErrorBoundary.js +6 -8
  12. package/dist/cjs/components/AnalyticsListener/LegacyAnalyticsListener.js +8 -11
  13. package/dist/cjs/components/AnalyticsListener/index.js +1 -1
  14. package/dist/cjs/components/matchEvent/index.js +23 -0
  15. package/dist/cjs/events/AnalyticsEvent.js +1 -2
  16. package/dist/cjs/events/UIAnalyticsEvent.js +12 -14
  17. package/dist/cjs/index.js +21 -0
  18. package/dist/cjs/utils/isModernContextEnabledEnv.js +1 -0
  19. package/dist/cjs/utils/withAnalytics.js +144 -0
  20. package/dist/es2019/components/AnalyticsContext/index.js +1 -1
  21. package/dist/es2019/components/AnalyticsDecorator/index.js +79 -0
  22. package/dist/es2019/components/AnalyticsDelegate/index.js +48 -0
  23. package/dist/es2019/components/AnalyticsErrorBoundary.js +1 -1
  24. package/dist/es2019/components/AnalyticsListener/index.js +1 -1
  25. package/dist/es2019/components/matchEvent/index.js +17 -0
  26. package/dist/es2019/events/UIAnalyticsEvent.js +1 -0
  27. package/dist/es2019/index.js +6 -1
  28. package/dist/es2019/utils/isModernContextEnabledEnv.js +1 -0
  29. package/dist/es2019/utils/withAnalytics.js +121 -0
  30. package/dist/esm/components/AnalyticsContext/LegacyAnalyticsContext.js +8 -11
  31. package/dist/esm/components/AnalyticsContext/index.js +1 -1
  32. package/dist/esm/components/AnalyticsDecorator/index.js +94 -0
  33. package/dist/esm/components/AnalyticsDelegate/index.js +62 -0
  34. package/dist/esm/components/AnalyticsErrorBoundary.js +6 -8
  35. package/dist/esm/components/AnalyticsListener/LegacyAnalyticsListener.js +8 -11
  36. package/dist/esm/components/AnalyticsListener/index.js +1 -1
  37. package/dist/esm/components/matchEvent/index.js +17 -0
  38. package/dist/esm/events/AnalyticsEvent.js +1 -2
  39. package/dist/esm/events/UIAnalyticsEvent.js +13 -14
  40. package/dist/esm/index.js +6 -1
  41. package/dist/esm/utils/isModernContextEnabledEnv.js +1 -0
  42. package/dist/esm/utils/withAnalytics.js +134 -0
  43. package/dist/types/components/AnalyticsDecorator/index.d.ts +46 -0
  44. package/dist/types/components/AnalyticsDelegate/index.d.ts +25 -0
  45. package/dist/types/components/matchEvent/index.d.ts +3 -0
  46. package/dist/types/hocs/withAnalyticsEvents.d.ts +1 -1
  47. package/dist/types/index.d.ts +3 -0
  48. package/dist/types/utils/withAnalytics.d.ts +80 -0
  49. package/dist/types-ts4.5/components/AnalyticsDecorator/index.d.ts +46 -0
  50. package/dist/types-ts4.5/components/AnalyticsDelegate/index.d.ts +25 -0
  51. package/dist/types-ts4.5/components/matchEvent/index.d.ts +3 -0
  52. package/dist/types-ts4.5/hocs/withAnalyticsEvents.d.ts +1 -1
  53. package/dist/types-ts4.5/index.d.ts +3 -0
  54. package/dist/types-ts4.5/utils/withAnalytics.d.ts +80 -0
  55. package/package.json +13 -5
  56. package/withAnalytics/package.json +15 -0
@@ -23,3 +23,6 @@ export { usePlatformLeafSyntheticEventHandler } from './hooks/usePlatformLeafSyn
23
23
  export type { UsePlatformLeafSyntheticEventHandlerHookArgs, UsePlatformLeafSyntheticEventHandlerHook, } from './hooks/usePlatformLeafSyntheticEventHandler';
24
24
  export { default as createAndFireEvent } from './utils/createAndFireEvent';
25
25
  export { default as cleanProps } from './utils/cleanProps';
26
+ export { default as AnalyticsDecorator } from './components/AnalyticsDecorator';
27
+ export { default as AnalyticsDelegate } from './components/AnalyticsDelegate';
28
+ export { default as withAnalytics } from './utils/withAnalytics';
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ type AnalyticsData = {
4
+ [key: string]: any;
5
+ };
6
+ type WithAnalyticsProps = {
7
+ analyticsId?: string;
8
+ analyticsData?: AnalyticsData;
9
+ fireAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
10
+ firePrivateAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
11
+ getParentAnalyticsData?: (name: string) => AnalyticsData;
12
+ delegateAnalyticsEvent?: (analyticsId: string, data: any, isPrivate: boolean) => void;
13
+ innerRef?: React.Ref<any>;
14
+ [key: string]: any;
15
+ };
16
+ type WithAnalyticsState = {
17
+ evaluatedMap: {
18
+ [key: string]: string | ((...args: any[]) => void);
19
+ };
20
+ };
21
+ /**
22
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
23
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
24
+ * for how to fire events, including handling the analyticsId and analyticsData
25
+ * props. The `map` argument may be an object or a function that returns an object.
26
+ * The properties of the `map` object/result can be strings (the name of the event
27
+ * that will be fired) or functions (which are responsible for firing the event).
28
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
29
+ * param. Please be aware that specifying a default `analyticsId` will cause public
30
+ * events to always fire for your component unless it has been set to a falsy by
31
+ * the component consumer.
32
+ *
33
+ * @param WrappedComponent
34
+ * @param map
35
+ * @param defaultProps
36
+ * @param withDelegation
37
+ */
38
+ declare const withAnalytics: (WrappedComponent: React.ComponentType<any>, map?: {
39
+ [key: string]: string | ((...args: any[]) => void);
40
+ } | ((fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void) => {
41
+ [key: string]: string | ((...args: any[]) => void);
42
+ }), defaultProps?: Partial<WithAnalyticsProps>, withDelegation?: boolean) => {
43
+ new (props: WithAnalyticsProps): {
44
+ componentDidMount(): void;
45
+ delegateAnalyticsEvent: (analyticsId: string, data: any, isPrivate: boolean) => void;
46
+ fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
47
+ privateAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
48
+ getParentAnalyticsData: (name: string) => AnalyticsData;
49
+ render(): JSX.Element;
50
+ context: any;
51
+ setState<K extends "evaluatedMap">(state: WithAnalyticsState | ((prevState: Readonly<WithAnalyticsState>, props: Readonly<WithAnalyticsProps>) => WithAnalyticsState | Pick<WithAnalyticsState, K> | null) | Pick<WithAnalyticsState, K> | null, callback?: (() => void) | undefined): void;
52
+ forceUpdate(callback?: (() => void) | undefined): void;
53
+ readonly props: Readonly<WithAnalyticsProps> & Readonly<{
54
+ children?: React.ReactNode;
55
+ }>;
56
+ state: Readonly<WithAnalyticsState>;
57
+ refs: {
58
+ [key: string]: React.ReactInstance;
59
+ };
60
+ shouldComponentUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): boolean;
61
+ componentWillUnmount?(): void;
62
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
63
+ getSnapshotBeforeUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>): any;
64
+ componentDidUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>, snapshot?: any): void;
65
+ componentWillMount?(): void;
66
+ UNSAFE_componentWillMount?(): void;
67
+ componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
68
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
69
+ componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
70
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
71
+ };
72
+ displayName: string;
73
+ contextTypes: {
74
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
75
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
76
+ };
77
+ defaultProps: Partial<WithAnalyticsProps>;
78
+ contextType?: React.Context<any> | undefined;
79
+ };
80
+ export default withAnalytics;
@@ -0,0 +1,46 @@
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { type Matcher } from '../matchEvent';
4
+ type AnalyticsData = {
5
+ [key: string]: any;
6
+ };
7
+ type AnalyticsDecoratorProps = {
8
+ match: Matcher;
9
+ matchPrivate: boolean;
10
+ data?: AnalyticsData;
11
+ getData?: (name: string, data: AnalyticsData) => AnalyticsData;
12
+ children: React.ReactNode;
13
+ };
14
+ type AnalyticsDecoratorContext = {
15
+ onAnalyticsEvent?: (name: string, data: AnalyticsData, isPrivate: boolean) => void;
16
+ getParentAnalyticsData?: (name: string, isPrivate: boolean) => AnalyticsData;
17
+ };
18
+ export declare const ContextTypes: {
19
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
20
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
21
+ };
22
+ /**
23
+ * The Decorator component extends analytics event data
24
+ * for any events fired by its descendents,
25
+ * then passes the event up the hierarchy
26
+ */
27
+ export declare class AnalyticsDecorator extends Component<AnalyticsDecoratorProps> {
28
+ static defaultProps: {
29
+ match: string;
30
+ matchPrivate: boolean;
31
+ };
32
+ static contextTypes: {
33
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
34
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
35
+ };
36
+ static childContextTypes: {
37
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
38
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
39
+ };
40
+ getChildContext(): AnalyticsDecoratorContext;
41
+ getDecoratedAnalyticsData: (name: string, srcData: AnalyticsData, isPrivate: boolean) => AnalyticsData;
42
+ onAnalyticsEvent: (name: string, srcData: AnalyticsData, isPrivate: boolean) => void;
43
+ getParentAnalyticsData: (name: string, isPrivate: boolean) => AnalyticsData;
44
+ render(): boolean | {} | React.ReactChild | React.ReactPortal | null | undefined;
45
+ }
46
+ export default AnalyticsDecorator;
@@ -0,0 +1,25 @@
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ type AnalyticsDelegateProps = {
4
+ delegateAnalyticsEvent?: (name: string, data: any, isPrivate: boolean) => void;
5
+ children: React.ReactNode;
6
+ };
7
+ type AnalyticsDelegateContext = {
8
+ onAnalyticsEvent?: (name: string, data: any, isPrivate: boolean) => void;
9
+ };
10
+ /**
11
+ * Listens to public and private events and delegates to an analytics
12
+ * stack in a different React root.
13
+ */
14
+ declare class AnalyticsDelegate extends Component<AnalyticsDelegateProps> {
15
+ static contextTypes: {
16
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
17
+ };
18
+ static childContextTypes: {
19
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
20
+ };
21
+ getChildContext(): AnalyticsDelegateContext;
22
+ onAnalyticsEvent: (name: string, data: any, isPrivate: boolean) => void;
23
+ render(): boolean | {} | React.ReactChild | React.ReactPortal | null | undefined;
24
+ }
25
+ export default AnalyticsDelegate;
@@ -0,0 +1,3 @@
1
+ export type Matcher = string | RegExp | ((name: string) => boolean) | '*';
2
+ declare function matchEvent(matcher: Matcher, name: string): boolean;
3
+ export default matchEvent;
@@ -8,5 +8,5 @@ export interface WithAnalyticsEventsProps {
8
8
  createAnalyticsEvent?: CreateUIAnalyticsEvent;
9
9
  ref?: React.Ref<any>;
10
10
  }
11
- declare const withAnalyticsEvents: (createEventMap?: CreateEventMap) => <Props extends WithAnalyticsEventsProps, Component>(WrappedComponent: React.ComponentType<Props> & Component) => React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<Component, Omit<Props, keyof WithAnalyticsEventsProps>>> & React.RefAttributes<any>>;
11
+ declare const withAnalyticsEvents: (createEventMap?: CreateEventMap) => <Props, Component>(WrappedComponent: React.ComponentType<WithAnalyticsEventsProps & Props> & Component) => React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<Component, Omit<Props, keyof WithAnalyticsEventsProps>>> & React.RefAttributes<any>>;
12
12
  export default withAnalyticsEvents;
@@ -23,3 +23,6 @@ export { usePlatformLeafSyntheticEventHandler } from './hooks/usePlatformLeafSyn
23
23
  export type { UsePlatformLeafSyntheticEventHandlerHookArgs, UsePlatformLeafSyntheticEventHandlerHook, } from './hooks/usePlatformLeafSyntheticEventHandler';
24
24
  export { default as createAndFireEvent } from './utils/createAndFireEvent';
25
25
  export { default as cleanProps } from './utils/cleanProps';
26
+ export { default as AnalyticsDecorator } from './components/AnalyticsDecorator';
27
+ export { default as AnalyticsDelegate } from './components/AnalyticsDelegate';
28
+ export { default as withAnalytics } from './utils/withAnalytics';
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ type AnalyticsData = {
4
+ [key: string]: any;
5
+ };
6
+ type WithAnalyticsProps = {
7
+ analyticsId?: string;
8
+ analyticsData?: AnalyticsData;
9
+ fireAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
10
+ firePrivateAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
11
+ getParentAnalyticsData?: (name: string) => AnalyticsData;
12
+ delegateAnalyticsEvent?: (analyticsId: string, data: any, isPrivate: boolean) => void;
13
+ innerRef?: React.Ref<any>;
14
+ [key: string]: any;
15
+ };
16
+ type WithAnalyticsState = {
17
+ evaluatedMap: {
18
+ [key: string]: string | ((...args: any[]) => void);
19
+ };
20
+ };
21
+ /**
22
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
23
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
24
+ * for how to fire events, including handling the analyticsId and analyticsData
25
+ * props. The `map` argument may be an object or a function that returns an object.
26
+ * The properties of the `map` object/result can be strings (the name of the event
27
+ * that will be fired) or functions (which are responsible for firing the event).
28
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
29
+ * param. Please be aware that specifying a default `analyticsId` will cause public
30
+ * events to always fire for your component unless it has been set to a falsy by
31
+ * the component consumer.
32
+ *
33
+ * @param WrappedComponent
34
+ * @param map
35
+ * @param defaultProps
36
+ * @param withDelegation
37
+ */
38
+ declare const withAnalytics: (WrappedComponent: React.ComponentType<any>, map?: {
39
+ [key: string]: string | ((...args: any[]) => void);
40
+ } | ((fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void) => {
41
+ [key: string]: string | ((...args: any[]) => void);
42
+ }), defaultProps?: Partial<WithAnalyticsProps>, withDelegation?: boolean) => {
43
+ new (props: WithAnalyticsProps): {
44
+ componentDidMount(): void;
45
+ delegateAnalyticsEvent: (analyticsId: string, data: any, isPrivate: boolean) => void;
46
+ fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
47
+ privateAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
48
+ getParentAnalyticsData: (name: string) => AnalyticsData;
49
+ render(): JSX.Element;
50
+ context: any;
51
+ setState<K extends "evaluatedMap">(state: WithAnalyticsState | ((prevState: Readonly<WithAnalyticsState>, props: Readonly<WithAnalyticsProps>) => WithAnalyticsState | Pick<WithAnalyticsState, K> | null) | Pick<WithAnalyticsState, K> | null, callback?: (() => void) | undefined): void;
52
+ forceUpdate(callback?: (() => void) | undefined): void;
53
+ readonly props: Readonly<WithAnalyticsProps> & Readonly<{
54
+ children?: React.ReactNode;
55
+ }>;
56
+ state: Readonly<WithAnalyticsState>;
57
+ refs: {
58
+ [key: string]: React.ReactInstance;
59
+ };
60
+ shouldComponentUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): boolean;
61
+ componentWillUnmount?(): void;
62
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
63
+ getSnapshotBeforeUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>): any;
64
+ componentDidUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>, snapshot?: any): void;
65
+ componentWillMount?(): void;
66
+ UNSAFE_componentWillMount?(): void;
67
+ componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
68
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
69
+ componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
70
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
71
+ };
72
+ displayName: string;
73
+ contextTypes: {
74
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
75
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
76
+ };
77
+ defaultProps: Partial<WithAnalyticsProps>;
78
+ contextType?: React.Context<any> | undefined;
79
+ };
80
+ export default withAnalytics;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/analytics-next",
3
- "version": "10.1.1",
3
+ "version": "10.2.1",
4
4
  "description": "React components, HOCs and hooks to assist with tracking user activity with React components",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -33,6 +33,9 @@
33
33
  "af:exports": {
34
34
  "./types": "./src/types.ts",
35
35
  "./AnalyticsContext": "./src/components/AnalyticsContext/index.tsx",
36
+ "./AnalyticsDecorator": "./src/components/AnalyticsDecorator/index.ts",
37
+ "./AnalyticsDelegate": "./src/components/AnalyticsDelegate/index.ts",
38
+ "./withAnalytics": "./src/utils/withAnalytics.tsx",
36
39
  "./AnalyticsListener": "./src/components/AnalyticsListener/index.tsx",
37
40
  "./AnalyticsErrorBoundary": "./src/components/AnalyticsErrorBoundary.tsx",
38
41
  "./withAnalyticsEvents": "./src/hocs/withAnalyticsEvents.tsx",
@@ -54,16 +57,21 @@
54
57
  "use-memo-one": "^1.1.1"
55
58
  },
56
59
  "peerDependencies": {
57
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
58
- "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
60
+ "react": "^16.8.0 || ^17.0.0 || ^18.2.0",
61
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.2.0"
59
62
  },
60
63
  "devDependencies": {
61
64
  "@atlaskit/ssr": "*",
62
65
  "@atlassian/feature-flags-test-utils": "*",
63
66
  "@testing-library/react": "^12.1.5",
64
- "storybook-addon-performance": "^0.16.0",
67
+ "storybook-addon-performance": "^0.17.3",
65
68
  "typescript": "~5.4.2"
66
69
  },
70
+ "overrides": {
71
+ "@atlaskit/analytics-next-stable-react-context": {
72
+ "react": "^18.2.0"
73
+ }
74
+ },
67
75
  "techstack": {
68
76
  "@atlassian/frontend": {
69
77
  "import-structure": "atlassian-conventions"
@@ -87,7 +95,7 @@
87
95
  }
88
96
  },
89
97
  "platform-feature-flags": {
90
- "platform.analytics-next-use-modern-context_fqgbx": {
98
+ "analytics-next-use-modern-context_jira": {
91
99
  "type": "boolean"
92
100
  }
93
101
  }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/analytics-next/withAnalytics",
3
+ "main": "../dist/cjs/utils/withAnalytics.js",
4
+ "module": "../dist/esm/utils/withAnalytics.js",
5
+ "module:es2019": "../dist/es2019/utils/withAnalytics.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/utils/withAnalytics.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <5.4": {
10
+ "*": [
11
+ "../dist/types-ts4.5/utils/withAnalytics.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }