@atlaskit/smart-card 21.2.0 → 22.1.0

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 (128) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/cjs/extractors/block/index.js +6 -7
  3. package/dist/cjs/extractors/common/actions/extractPreviewAction.js +16 -19
  4. package/dist/cjs/state/actions/index.js +54 -10
  5. package/dist/cjs/state/analytics/types.js +5 -0
  6. package/dist/cjs/state/analytics/useSmartLinkAnalytics.js +429 -109
  7. package/dist/cjs/state/hooks-external/useSmartLinkActions.js +5 -3
  8. package/dist/cjs/utils/analytics/analytics.js +241 -74
  9. package/dist/cjs/utils/analytics/index.js +32 -5
  10. package/dist/cjs/utils/mocks.js +28 -2
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/cjs/view/BlockCard/actions/PreviewAction.js +2 -2
  13. package/dist/cjs/view/BlockCard/index.js +6 -5
  14. package/dist/cjs/view/CardWithUrl/component.js +27 -5
  15. package/dist/cjs/view/CardWithUrl/loader.js +6 -1
  16. package/dist/cjs/view/EmbedCard/index.js +3 -2
  17. package/dist/cjs/view/EmbedModal/components/analytics/index.js +100 -0
  18. package/dist/cjs/view/EmbedModal/components/analytics/types.js +5 -0
  19. package/dist/cjs/view/EmbedModal/components/size-experiment/index.js +5 -10
  20. package/dist/cjs/view/EmbedModal/index.js +54 -15
  21. package/dist/cjs/view/EmbedModal/types.js +9 -1
  22. package/dist/cjs/view/FlexibleCard/components/blocks/block/index.js +17 -3
  23. package/dist/cjs/view/FlexibleCard/components/blocks/preview-block/index.js +5 -2
  24. package/dist/cjs/view/FlexibleCard/components/common/image-icon/index.js +4 -2
  25. package/dist/cjs/view/FlexibleCard/components/common/loading-skeleton/index.js +1 -2
  26. package/dist/cjs/view/FlexibleCard/components/elements/media/index.js +5 -2
  27. package/dist/cjs/view/HoverCard/components/HoverCardComponent.js +11 -3
  28. package/dist/cjs/view/HoverCard/components/HoverCardContent.js +36 -8
  29. package/dist/cjs/view/HoverCard/components/SnippetOrPreview.js +74 -0
  30. package/dist/cjs/view/HoverCard/index.js +6 -1
  31. package/dist/cjs/view/HoverCard/styled.js +11 -3
  32. package/dist/cjs/view/common/Modal.js +29 -4
  33. package/dist/cjs/view/common/ModalHeader.js +3 -2
  34. package/dist/es2019/extractors/block/index.js +6 -7
  35. package/dist/es2019/extractors/common/actions/extractPreviewAction.js +16 -10
  36. package/dist/es2019/state/actions/index.js +54 -10
  37. package/dist/es2019/state/analytics/types.js +1 -0
  38. package/dist/es2019/state/analytics/useSmartLinkAnalytics.js +424 -41
  39. package/dist/es2019/state/hooks-external/useSmartLinkActions.js +5 -3
  40. package/dist/es2019/utils/analytics/analytics.js +254 -79
  41. package/dist/es2019/utils/analytics/index.js +32 -4
  42. package/dist/es2019/utils/mocks.js +26 -1
  43. package/dist/es2019/version.json +1 -1
  44. package/dist/es2019/view/BlockCard/actions/PreviewAction.js +3 -3
  45. package/dist/es2019/view/BlockCard/index.js +5 -4
  46. package/dist/es2019/view/CardWithUrl/component.js +27 -5
  47. package/dist/es2019/view/CardWithUrl/loader.js +6 -1
  48. package/dist/es2019/view/EmbedCard/index.js +3 -2
  49. package/dist/es2019/view/EmbedModal/components/analytics/index.js +80 -0
  50. package/dist/es2019/view/EmbedModal/components/analytics/types.js +1 -0
  51. package/dist/es2019/view/EmbedModal/components/size-experiment/index.js +5 -9
  52. package/dist/es2019/view/EmbedModal/index.js +46 -13
  53. package/dist/es2019/view/EmbedModal/types.js +6 -1
  54. package/dist/es2019/view/FlexibleCard/components/blocks/block/index.js +17 -7
  55. package/dist/es2019/view/FlexibleCard/components/blocks/preview-block/index.js +4 -1
  56. package/dist/es2019/view/FlexibleCard/components/common/image-icon/index.js +4 -2
  57. package/dist/es2019/view/FlexibleCard/components/common/loading-skeleton/index.js +2 -3
  58. package/dist/es2019/view/FlexibleCard/components/elements/media/index.js +5 -2
  59. package/dist/es2019/view/HoverCard/components/HoverCardComponent.js +11 -3
  60. package/dist/es2019/view/HoverCard/components/HoverCardContent.js +36 -10
  61. package/dist/es2019/view/HoverCard/components/SnippetOrPreview.js +42 -0
  62. package/dist/es2019/view/HoverCard/index.js +6 -1
  63. package/dist/es2019/view/HoverCard/styled.js +8 -0
  64. package/dist/es2019/view/common/Modal.js +27 -6
  65. package/dist/es2019/view/common/ModalHeader.js +3 -2
  66. package/dist/esm/extractors/block/index.js +6 -7
  67. package/dist/esm/extractors/common/actions/extractPreviewAction.js +17 -19
  68. package/dist/esm/state/actions/index.js +54 -10
  69. package/dist/esm/state/analytics/types.js +1 -0
  70. package/dist/esm/state/analytics/useSmartLinkAnalytics.js +428 -111
  71. package/dist/esm/state/hooks-external/useSmartLinkActions.js +5 -3
  72. package/dist/esm/utils/analytics/analytics.js +241 -74
  73. package/dist/esm/utils/analytics/index.js +31 -4
  74. package/dist/esm/utils/mocks.js +25 -0
  75. package/dist/esm/version.json +1 -1
  76. package/dist/esm/view/BlockCard/actions/PreviewAction.js +3 -3
  77. package/dist/esm/view/BlockCard/index.js +5 -4
  78. package/dist/esm/view/CardWithUrl/component.js +27 -5
  79. package/dist/esm/view/CardWithUrl/loader.js +6 -1
  80. package/dist/esm/view/EmbedCard/index.js +3 -2
  81. package/dist/esm/view/EmbedModal/components/analytics/index.js +82 -0
  82. package/dist/esm/view/EmbedModal/components/analytics/types.js +1 -0
  83. package/dist/esm/view/EmbedModal/components/size-experiment/index.js +5 -10
  84. package/dist/esm/view/EmbedModal/index.js +52 -15
  85. package/dist/esm/view/EmbedModal/types.js +6 -1
  86. package/dist/esm/view/FlexibleCard/components/blocks/block/index.js +11 -3
  87. package/dist/esm/view/FlexibleCard/components/blocks/preview-block/index.js +5 -2
  88. package/dist/esm/view/FlexibleCard/components/common/image-icon/index.js +4 -2
  89. package/dist/esm/view/FlexibleCard/components/common/loading-skeleton/index.js +1 -2
  90. package/dist/esm/view/FlexibleCard/components/elements/media/index.js +5 -2
  91. package/dist/esm/view/HoverCard/components/HoverCardComponent.js +11 -3
  92. package/dist/esm/view/HoverCard/components/HoverCardContent.js +36 -10
  93. package/dist/esm/view/HoverCard/components/SnippetOrPreview.js +53 -0
  94. package/dist/esm/view/HoverCard/index.js +6 -1
  95. package/dist/esm/view/HoverCard/styled.js +6 -2
  96. package/dist/esm/view/common/Modal.js +28 -6
  97. package/dist/esm/view/common/ModalHeader.js +3 -2
  98. package/dist/types/extractors/block/types.d.ts +4 -2
  99. package/dist/types/extractors/common/actions/extractPreviewAction.d.ts +7 -5
  100. package/dist/types/state/analytics/types.d.ts +9 -0
  101. package/dist/types/state/analytics/useSmartLinkAnalytics.d.ts +41 -24
  102. package/dist/types/state/hooks/useSmartLink.d.ts +26 -18
  103. package/dist/types/state/hooks-external/useSmartLinkActions.d.ts +6 -2
  104. package/dist/types/utils/analytics/analytics.d.ts +19 -21
  105. package/dist/types/utils/analytics/index.d.ts +2 -2
  106. package/dist/types/utils/analytics/types.d.ts +91 -0
  107. package/dist/types/utils/mocks.d.ts +48 -0
  108. package/dist/types/utils/types.d.ts +3 -1
  109. package/dist/types/view/BlockCard/actions/PreviewAction.d.ts +4 -0
  110. package/dist/types/view/BlockCard/index.d.ts +2 -2
  111. package/dist/types/view/BlockCard/types.d.ts +4 -4
  112. package/dist/types/view/Card/index.d.ts +1 -1
  113. package/dist/types/view/EmbedCard/types.d.ts +2 -2
  114. package/dist/types/view/EmbedModal/components/analytics/index.d.ts +5 -0
  115. package/dist/types/view/EmbedModal/components/analytics/types.d.ts +6 -0
  116. package/dist/types/view/EmbedModal/components/size-experiment/index.d.ts +4 -3
  117. package/dist/types/view/EmbedModal/index.d.ts +3 -1
  118. package/dist/types/view/EmbedModal/types.d.ts +14 -4
  119. package/dist/types/view/FlexibleCard/components/blocks/preview-block/types.d.ts +7 -1
  120. package/dist/types/view/FlexibleCard/components/blocks/types.d.ts +15 -0
  121. package/dist/types/view/FlexibleCard/components/common/image-icon/types.d.ts +1 -0
  122. package/dist/types/view/FlexibleCard/components/elements/media/types.d.ts +5 -0
  123. package/dist/types/view/HoverCard/components/SnippetOrPreview.d.ts +4 -0
  124. package/dist/types/view/HoverCard/styled.d.ts +2 -0
  125. package/dist/types/view/HoverCard/types.d.ts +5 -0
  126. package/dist/types/view/common/Modal.d.ts +6 -8
  127. package/package.json +1 -1
  128. package/report.api.md +324 -108
@@ -1,9 +1,21 @@
1
1
  import { useMemo } from 'react';
2
2
  import { getUrl } from '@atlaskit/linking-common';
3
- import { uiAuthEvent, uiAuthAlternateAccountEvent, uiCardClickedEvent, uiActionClickedEvent, uiClosedAuthEvent, uiRenderSuccessEvent, uiRenderFailedEvent, uiHoverCardViewedEvent, uiHoverCardDismissedEvent, uiHoverCardOpenLinkClickedEvent, invokeSucceededEvent, invokeFailedEvent, connectSucceededEvent, connectFailedEvent, trackAppAccountConnected, screenAuthPopupEvent, instrumentEvent } from '../../utils/analytics';
3
+ import { connectFailedEvent, connectSucceededEvent, context, instrumentEvent, invokeFailedEvent, invokeSucceededEvent, screenAuthPopupEvent, trackAppAccountConnected, uiActionClickedEvent, uiAuthAlternateAccountEvent, uiAuthEvent, uiCardClickedEvent, uiClosedAuthEvent, uiHoverCardDismissedEvent, uiHoverCardOpenLinkClickedEvent, uiHoverCardViewedEvent, uiRenderFailedEvent, uiRenderSuccessEvent } from '../../utils/analytics';
4
4
  import { failUfoExperience, startUfoExperience, succeedUfoExperience } from './ufoExperiences';
5
- import { getDefinitionId, getExtensionKey, getResourceType, getSubproduct, getProduct } from '../helpers';
5
+ import { getDefinitionId, getExtensionKey, getProduct, getResourceType, getSubproduct } from '../helpers';
6
6
  import { useSmartLinkContext } from '@atlaskit/link-provider';
7
+
8
+ const applyCommonAttributes = (event, commonAttributes) => {
9
+ if (event && event.attributes) {
10
+ for (const [key, value] of Object.entries(commonAttributes)) {
11
+ if (event.attributes[key] === undefined) {
12
+ event.attributes[key] = value;
13
+ }
14
+ }
15
+ }
16
+
17
+ return event;
18
+ };
7
19
  /**
8
20
  * This hook provides usage of Smart Link analytics outside of the Card component.
9
21
  * Can be provided to Card via the analyticsEvents prop to change the analytics events.
@@ -14,6 +26,7 @@ import { useSmartLinkContext } from '@atlaskit/link-provider';
14
26
  * @returns
15
27
  */
16
28
 
29
+
17
30
  export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocation) => {
18
31
  const defaultId = id || 'NULL'; // We don't want to trigger a re-render by using useSmartCardState
19
32
 
@@ -27,6 +40,15 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
27
40
  const extractedResourceType = getResourceType(details);
28
41
  const extractedSubproduct = getSubproduct(details);
29
42
  const extractedProduct = getProduct(details);
43
+ const commonAttributes = useMemo(() => ({
44
+ id: defaultId,
45
+ definitionId: extractedDefinitionId,
46
+ extensionKey: extractedExtensionKey,
47
+ resourceType: extractedResourceType,
48
+ destinationSubproduct: extractedSubproduct,
49
+ destinationProduct: extractedProduct,
50
+ location: defaultLocation
51
+ }), [defaultId, extractedDefinitionId, extractedExtensionKey, extractedResourceType, extractedSubproduct, extractedProduct, defaultLocation]);
30
52
  /** Contains all ui analytics events */
31
53
 
32
54
  const ui = useMemo(() => ({
@@ -38,7 +60,23 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
38
60
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
39
61
  * @returns
40
62
  */
41
- authEvent: (display, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => dispatchAnalytics(uiAuthEvent(display, definitionId, extensionKey)),
63
+ authEvent: ({
64
+ display,
65
+ extensionKey,
66
+ definitionId,
67
+ resourceType,
68
+ destinationProduct,
69
+ destinationSubproduct,
70
+ location
71
+ }) => dispatchAnalytics(applyCommonAttributes(uiAuthEvent({
72
+ display,
73
+ extensionKey,
74
+ definitionId,
75
+ resourceType,
76
+ destinationProduct,
77
+ destinationSubproduct,
78
+ location
79
+ }), commonAttributes)),
42
80
 
43
81
  /**
44
82
  * This fires an event that represents when a user clicks on the authentication
@@ -48,7 +86,38 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
48
86
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
49
87
  * @returns
50
88
  */
51
- authAlternateAccountEvent: (display, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => dispatchAnalytics(uiAuthAlternateAccountEvent(display, definitionId, extensionKey)),
89
+ authAlternateAccountEvent: ({
90
+ display,
91
+ extensionKey,
92
+ definitionId,
93
+ resourceType,
94
+ destinationProduct,
95
+ destinationSubproduct,
96
+ location
97
+ }) => dispatchAnalytics(applyCommonAttributes(uiAuthAlternateAccountEvent({
98
+ display,
99
+ extensionKey,
100
+ definitionId,
101
+ resourceType,
102
+ destinationProduct,
103
+ destinationSubproduct,
104
+ location
105
+ }), commonAttributes)),
106
+
107
+ /**
108
+ * This fires an event that represents when a user
109
+ * click a button.
110
+ * @param data A partial analytics event payload
111
+ */
112
+ buttonClickedEvent: data => dispatchAnalytics(applyCommonAttributes({
113
+ action: 'clicked',
114
+ actionSubject: 'button',
115
+ actionSubjectId: data.actionSubjectId,
116
+ attributes: { ...context,
117
+ ...data.attributes
118
+ },
119
+ eventType: 'ui'
120
+ }, commonAttributes)),
52
121
 
53
122
  /**
54
123
  * This fires an event that represents when a user clicks on a Smart Link.
@@ -62,7 +131,29 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
62
131
  * @param destinationProduct The product the Smart Link is linked to.
63
132
  * @returns
64
133
  */
65
- cardClickedEvent: (id = defaultId, display, status, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey, isModifierKeyPressed, location = defaultLocation, destinationProduct = extractedProduct, destinationSubproduct = extractedSubproduct, actionSubjectId) => dispatchAnalytics(uiCardClickedEvent(id, display, status, definitionId, extensionKey, isModifierKeyPressed, location, destinationProduct, destinationSubproduct, actionSubjectId)),
134
+ cardClickedEvent: ({
135
+ id,
136
+ display,
137
+ status,
138
+ definitionId,
139
+ extensionKey,
140
+ isModifierKeyPressed,
141
+ location,
142
+ destinationProduct,
143
+ destinationSubproduct,
144
+ actionSubjectId
145
+ }) => dispatchAnalytics(applyCommonAttributes(uiCardClickedEvent({
146
+ id,
147
+ display,
148
+ status,
149
+ definitionId,
150
+ extensionKey,
151
+ isModifierKeyPressed,
152
+ location,
153
+ destinationProduct,
154
+ destinationSubproduct,
155
+ actionSubjectId
156
+ }), commonAttributes)),
66
157
 
67
158
  /**
68
159
  * This fires an event that represents when a user clicks on a Smart Link action.
@@ -74,14 +165,35 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
74
165
  * @param invokeType Whether the action invoked made a call to a server.
75
166
  * @returns
76
167
  */
77
- actionClickedEvent: (id = defaultId, extensionKey = extractedExtensionKey, actionType, display, invokeType) => {
168
+ actionClickedEvent: ({
169
+ id,
170
+ actionType,
171
+ display,
172
+ invokeType,
173
+ extensionKey,
174
+ definitionId,
175
+ resourceType,
176
+ destinationProduct,
177
+ destinationSubproduct,
178
+ location
179
+ }) => {
78
180
  startUfoExperience('smart-link-action-invocation', id, {
79
181
  actionType,
80
182
  display,
81
183
  extensionKey,
82
184
  invokeType
83
185
  });
84
- dispatchAnalytics(uiActionClickedEvent(id, actionType, extensionKey, display));
186
+ dispatchAnalytics(applyCommonAttributes(uiActionClickedEvent({
187
+ id,
188
+ actionType,
189
+ display,
190
+ extensionKey,
191
+ definitionId,
192
+ resourceType,
193
+ destinationProduct,
194
+ destinationSubproduct,
195
+ location
196
+ }), commonAttributes));
85
197
  },
86
198
 
87
199
  /**
@@ -92,8 +204,25 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
92
204
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
93
205
  * @param previewInvokeMethod How the preview was triggered.
94
206
  */
95
- hoverCardOpenLinkClickedEvent: (previewDisplay, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey, previewInvokeMethod) => {
96
- dispatchAnalytics(uiHoverCardOpenLinkClickedEvent(defaultId, previewDisplay, definitionId, extensionKey, previewInvokeMethod));
207
+ hoverCardOpenLinkClickedEvent: ({
208
+ previewDisplay,
209
+ definitionId,
210
+ extensionKey,
211
+ destinationProduct,
212
+ destinationSubproduct,
213
+ location,
214
+ previewInvokeMethod
215
+ }) => {
216
+ dispatchAnalytics(applyCommonAttributes(uiHoverCardOpenLinkClickedEvent({
217
+ id: defaultId,
218
+ previewDisplay,
219
+ definitionId,
220
+ extensionKey,
221
+ destinationProduct,
222
+ destinationSubproduct,
223
+ location,
224
+ previewInvokeMethod
225
+ }), commonAttributes));
97
226
  },
98
227
 
99
228
  /**
@@ -103,7 +232,37 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
103
232
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
104
233
  * @returns
105
234
  */
106
- closedAuthEvent: (display, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => dispatchAnalytics(uiClosedAuthEvent(display, definitionId, extensionKey)),
235
+ closedAuthEvent: ({
236
+ display,
237
+ extensionKey,
238
+ definitionId,
239
+ resourceType,
240
+ destinationProduct,
241
+ destinationSubproduct,
242
+ location
243
+ }) => dispatchAnalytics(applyCommonAttributes(uiClosedAuthEvent({
244
+ display,
245
+ extensionKey,
246
+ definitionId,
247
+ resourceType,
248
+ destinationProduct,
249
+ destinationSubproduct,
250
+ location
251
+ }), commonAttributes)),
252
+
253
+ /**
254
+ * This fires an event that represents when a user close a modal.
255
+ * @param data A partial analytics event payload
256
+ */
257
+ modalClosedEvent: data => dispatchAnalytics(applyCommonAttributes({
258
+ action: 'closed',
259
+ actionSubject: 'modal',
260
+ actionSubjectId: data.actionSubjectId,
261
+ attributes: { ...context,
262
+ ...data.attributes
263
+ },
264
+ eventType: 'ui'
265
+ }, commonAttributes)),
107
266
 
108
267
  /**
109
268
  * This fires an event that represents when a Smart Link was rendered successfully.
@@ -113,16 +272,36 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
113
272
  * @param definitionId The definitionId of the Smart Link resolver invoked.
114
273
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
115
274
  */
116
- renderSuccessEvent: (display, status, id = defaultId, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => {
117
- succeedUfoExperience('smart-link-rendered', id, {
275
+ renderSuccessEvent: ({
276
+ display,
277
+ status,
278
+ id,
279
+ extensionKey,
280
+ definitionId,
281
+ resourceType,
282
+ destinationProduct,
283
+ destinationSubproduct,
284
+ location
285
+ }) => {
286
+ const experienceId = id ? id : defaultId;
287
+ succeedUfoExperience('smart-link-rendered', experienceId, {
118
288
  extensionKey,
119
289
  display
120
290
  }); // UFO will disregard this if authentication experience has not yet been started
121
291
 
122
- succeedUfoExperience('smart-link-authenticated', id, {
292
+ succeedUfoExperience('smart-link-authenticated', experienceId, {
123
293
  display
124
294
  });
125
- dispatchAnalytics(uiRenderSuccessEvent(display, status, definitionId, extensionKey));
295
+ dispatchAnalytics(applyCommonAttributes(uiRenderSuccessEvent({
296
+ display,
297
+ status,
298
+ extensionKey,
299
+ definitionId,
300
+ resourceType,
301
+ destinationProduct,
302
+ destinationSubproduct,
303
+ location
304
+ }), commonAttributes));
126
305
  },
127
306
 
128
307
  /**
@@ -132,13 +311,35 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
132
311
  * @param error: An error representing why the Smart Link render failed.
133
312
  * @param errorInfo: Additional details about the error including the stack trace.
134
313
  */
135
- renderFailedEvent: (display, id = defaultId, error, errorInfo) => {
136
- // Start and fail the smart-link-rendered experience. If it has already
314
+ renderFailedEvent: ({
315
+ display,
316
+ id,
317
+ error,
318
+ errorInfo,
319
+ extensionKey,
320
+ definitionId,
321
+ resourceType,
322
+ destinationProduct,
323
+ destinationSubproduct,
324
+ location
325
+ }) => {
326
+ const experienceId = id ? id : defaultId; // Start and fail the smart-link-rendered experience. If it has already
137
327
  // been started nothing happens.
138
- startUfoExperience('smart-link-rendered', id);
139
- failUfoExperience('smart-link-rendered', id);
140
- failUfoExperience('smart-link-authenticated', id);
141
- dispatchAnalytics(uiRenderFailedEvent(display, error, errorInfo));
328
+
329
+ startUfoExperience('smart-link-rendered', experienceId);
330
+ failUfoExperience('smart-link-rendered', experienceId);
331
+ failUfoExperience('smart-link-authenticated', experienceId);
332
+ dispatchAnalytics(applyCommonAttributes(uiRenderFailedEvent({
333
+ display,
334
+ error,
335
+ errorInfo,
336
+ extensionKey,
337
+ definitionId,
338
+ resourceType,
339
+ destinationProduct,
340
+ destinationSubproduct,
341
+ location
342
+ }), commonAttributes));
142
343
  },
143
344
 
144
345
  /**
@@ -149,7 +350,27 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
149
350
  * @param previewInvokeMethod How the preview was triggered.
150
351
  * @returns
151
352
  */
152
- hoverCardViewedEvent: (previewDisplay, previewInvokeMethod, id = defaultId, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => dispatchAnalytics(uiHoverCardViewedEvent(id, previewDisplay, definitionId, extensionKey, previewInvokeMethod)),
353
+ hoverCardViewedEvent: ({
354
+ previewDisplay,
355
+ previewInvokeMethod,
356
+ id,
357
+ extensionKey,
358
+ definitionId,
359
+ resourceType,
360
+ destinationProduct,
361
+ destinationSubproduct,
362
+ location
363
+ }) => dispatchAnalytics(applyCommonAttributes(uiHoverCardViewedEvent({
364
+ id,
365
+ previewDisplay,
366
+ extensionKey,
367
+ definitionId,
368
+ resourceType,
369
+ destinationProduct,
370
+ destinationSubproduct,
371
+ location,
372
+ previewInvokeMethod
373
+ }), commonAttributes)),
153
374
 
154
375
  /**
155
376
  * This fires an event that represents a hover preview being dismissed.
@@ -160,8 +381,30 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
160
381
  * @param previewInvokeMethod How the preview was triggered.
161
382
  * @returns
162
383
  */
163
- hoverCardDismissedEvent: (previewDisplay, hoverTime, previewInvokeMethod, id = defaultId, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => dispatchAnalytics(uiHoverCardDismissedEvent(id, previewDisplay, hoverTime, definitionId, extensionKey, previewInvokeMethod))
164
- }), [extractedDefinitionId, extractedExtensionKey, dispatchAnalytics, defaultId, defaultLocation, extractedProduct, extractedSubproduct]);
384
+ hoverCardDismissedEvent: ({
385
+ id,
386
+ previewDisplay,
387
+ hoverTime,
388
+ previewInvokeMethod,
389
+ extensionKey,
390
+ definitionId,
391
+ resourceType,
392
+ destinationProduct,
393
+ destinationSubproduct,
394
+ location
395
+ }) => dispatchAnalytics(applyCommonAttributes(uiHoverCardDismissedEvent({
396
+ previewDisplay,
397
+ id,
398
+ hoverTime,
399
+ extensionKey,
400
+ definitionId,
401
+ resourceType,
402
+ destinationProduct,
403
+ destinationSubproduct,
404
+ location,
405
+ previewInvokeMethod
406
+ }), commonAttributes))
407
+ }), [defaultId, commonAttributes, dispatchAnalytics]);
165
408
  /** Contains all operational analytics events */
166
409
 
167
410
  const operational = useMemo(() => ({
@@ -172,9 +415,29 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
172
415
  * @param actionType The type of action invoked, e.g. PreviewAction
173
416
  * @param display Whether the card was an Inline, Block, Embed or Flexible UI.
174
417
  */
175
- invokeSucceededEvent: (id = defaultId, extensionKey = extractedExtensionKey, actionType, display) => {
418
+ invokeSucceededEvent: ({
419
+ id,
420
+ actionType,
421
+ display,
422
+ extensionKey,
423
+ definitionId,
424
+ resourceType,
425
+ destinationProduct,
426
+ destinationSubproduct,
427
+ location
428
+ }) => {
176
429
  succeedUfoExperience('smart-link-action-invocation', id);
177
- dispatchAnalytics(invokeSucceededEvent(id, actionType, display, extensionKey));
430
+ dispatchAnalytics(applyCommonAttributes(invokeSucceededEvent({
431
+ id,
432
+ actionType,
433
+ display,
434
+ extensionKey,
435
+ definitionId,
436
+ resourceType,
437
+ destinationProduct,
438
+ destinationSubproduct,
439
+ location
440
+ }), commonAttributes));
178
441
  },
179
442
 
180
443
  /**
@@ -185,9 +448,31 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
185
448
  * @param display Whether the card was an Inline, Block, Embed or Flexible UI.
186
449
  * @param reason The reason the invocation failed.
187
450
  */
188
- invokeFailedEvent: (id = defaultId, providerKey = extractedExtensionKey, actionType, display, reason) => {
451
+ invokeFailedEvent: ({
452
+ id,
453
+ actionType,
454
+ display,
455
+ reason,
456
+ extensionKey,
457
+ definitionId,
458
+ resourceType,
459
+ destinationProduct,
460
+ destinationSubproduct,
461
+ location
462
+ }) => {
189
463
  failUfoExperience('smart-link-action-invocation', id);
190
- dispatchAnalytics(invokeFailedEvent(id, actionType, display, reason, providerKey));
464
+ dispatchAnalytics(applyCommonAttributes(invokeFailedEvent({
465
+ id,
466
+ actionType,
467
+ display,
468
+ reason,
469
+ extensionKey,
470
+ definitionId,
471
+ resourceType,
472
+ destinationProduct,
473
+ destinationSubproduct,
474
+ location
475
+ }), commonAttributes));
191
476
  },
192
477
 
193
478
  /**
@@ -196,12 +481,29 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
196
481
  * @param definitionId The definitionId of the Smart Link resolver invoked.
197
482
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
198
483
  */
199
- connectSucceededEvent: (id = defaultId, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => {
200
- startUfoExperience('smart-link-authenticated', id, {
484
+ connectSucceededEvent: ({
485
+ id,
486
+ extensionKey,
487
+ definitionId,
488
+ resourceType,
489
+ destinationProduct,
490
+ destinationSubproduct,
491
+ location
492
+ }) => {
493
+ const experienceId = id ? id : defaultId;
494
+ startUfoExperience('smart-link-authenticated', experienceId, {
201
495
  extensionKey,
202
496
  status: 'success'
203
497
  });
204
- dispatchAnalytics(connectSucceededEvent(definitionId, extensionKey));
498
+ dispatchAnalytics(applyCommonAttributes(connectSucceededEvent({ ...commonAttributes,
499
+ id: experienceId,
500
+ extensionKey,
501
+ definitionId,
502
+ resourceType,
503
+ destinationProduct,
504
+ destinationSubproduct,
505
+ location
506
+ }), commonAttributes));
205
507
  },
206
508
 
207
509
  /**
@@ -211,12 +513,31 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
211
513
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
212
514
  * @param reason The reason why the Smart Link connect account failed.
213
515
  */
214
- connectFailedEvent: (id = defaultId, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey, reason) => {
215
- startUfoExperience('smart-link-authenticated', id, {
516
+ connectFailedEvent: ({
517
+ id,
518
+ reason,
519
+ extensionKey,
520
+ definitionId,
521
+ resourceType,
522
+ destinationProduct,
523
+ destinationSubproduct,
524
+ location
525
+ }) => {
526
+ const experienceId = id ? id : defaultId;
527
+ startUfoExperience('smart-link-authenticated', experienceId, {
216
528
  extensionKey,
217
529
  status: reason
218
530
  });
219
- dispatchAnalytics(connectFailedEvent(definitionId, extensionKey, reason));
531
+ dispatchAnalytics(applyCommonAttributes(connectFailedEvent({ ...commonAttributes,
532
+ id: experienceId,
533
+ reason,
534
+ extensionKey,
535
+ definitionId,
536
+ resourceType,
537
+ destinationProduct,
538
+ destinationSubproduct,
539
+ location
540
+ }), commonAttributes));
220
541
  },
221
542
 
222
543
  /**
@@ -228,14 +549,34 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
228
549
  * @param resourceType The type of resource that was invoked. This is provider specific (e.g. File, PullRequest).
229
550
  * @param error An error representing why the Smart Link request failed.
230
551
  */
231
- instrument: (id = defaultId, status, definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey, resourceType = extractedResourceType, error) => {
232
- const event = instrumentEvent(id, status, definitionId, extensionKey, resourceType, error);
552
+ instrument: ({
553
+ id,
554
+ status,
555
+ extensionKey,
556
+ definitionId,
557
+ resourceType,
558
+ destinationProduct,
559
+ destinationSubproduct,
560
+ location,
561
+ error
562
+ }) => {
563
+ const event = instrumentEvent({ ...commonAttributes,
564
+ id,
565
+ status,
566
+ extensionKey,
567
+ definitionId,
568
+ resourceType,
569
+ destinationProduct,
570
+ destinationSubproduct,
571
+ location,
572
+ error
573
+ });
233
574
 
234
575
  if (event) {
235
- dispatchAnalytics(event);
576
+ dispatchAnalytics(applyCommonAttributes(event, commonAttributes));
236
577
  }
237
578
  }
238
- }), [defaultId, extractedResourceType, extractedDefinitionId, extractedExtensionKey, dispatchAnalytics]);
579
+ }), [defaultId, commonAttributes, dispatchAnalytics]);
239
580
  /** Contains all track analytics events */
240
581
 
241
582
  const track = useMemo(() => ({
@@ -245,8 +586,22 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
245
586
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
246
587
  * @returns
247
588
  */
248
- appAccountConnected: (definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => dispatchAnalytics(trackAppAccountConnected(definitionId, extensionKey))
249
- }), [extractedDefinitionId, extractedExtensionKey, dispatchAnalytics]);
589
+ appAccountConnected: ({
590
+ extensionKey,
591
+ definitionId,
592
+ resourceType,
593
+ destinationProduct,
594
+ destinationSubproduct,
595
+ location
596
+ }) => dispatchAnalytics(applyCommonAttributes(trackAppAccountConnected({ ...commonAttributes,
597
+ extensionKey,
598
+ definitionId,
599
+ resourceType,
600
+ destinationProduct,
601
+ destinationSubproduct,
602
+ location
603
+ }), commonAttributes))
604
+ }), [commonAttributes, dispatchAnalytics]);
250
605
  /** Contains all screen analytics events */
251
606
 
252
607
  const screen = useMemo(() => ({
@@ -256,8 +611,36 @@ export const useSmartLinkAnalytics = (url, dispatchAnalytics, id, defaultLocatio
256
611
  * @param extensionKey The extensionKey of the Smart Link resovler invoked.
257
612
  * @returns
258
613
  */
259
- authPopupEvent: (definitionId = extractedDefinitionId, extensionKey = extractedExtensionKey) => dispatchAnalytics(screenAuthPopupEvent(definitionId, extensionKey))
260
- }), [extractedDefinitionId, extractedExtensionKey, dispatchAnalytics]);
614
+ authPopupEvent: ({
615
+ extensionKey,
616
+ definitionId,
617
+ resourceType,
618
+ destinationProduct,
619
+ destinationSubproduct,
620
+ location
621
+ }) => dispatchAnalytics(applyCommonAttributes(screenAuthPopupEvent({ ...commonAttributes,
622
+ extensionKey,
623
+ definitionId,
624
+ resourceType,
625
+ destinationProduct,
626
+ destinationSubproduct,
627
+ location
628
+ }), commonAttributes)),
629
+
630
+ /**
631
+ * This fires an event that represents when a user view a modal.
632
+ * @param data A partial analytics event payload
633
+ */
634
+ modalViewedEvent: data => dispatchAnalytics(applyCommonAttributes({
635
+ action: 'viewed',
636
+ actionSubject: data.name,
637
+ attributes: { ...context,
638
+ ...data.attributes
639
+ },
640
+ eventType: 'screen',
641
+ name: data.name
642
+ }, commonAttributes))
643
+ }), [commonAttributes, dispatchAnalytics]);
261
644
  return useMemo(() => ({
262
645
  ui,
263
646
  operational,
@@ -10,7 +10,8 @@ export function useSmartLinkActions({
10
10
  url,
11
11
  appearance,
12
12
  analyticsHandler,
13
- platform = 'web'
13
+ platform = 'web',
14
+ origin
14
15
  }) {
15
16
  const id = useMemo(() => uuid(), []);
16
17
  const [actions, setActions] = useState([]);
@@ -32,7 +33,8 @@ export function useSmartLinkActions({
32
33
  const cardProperties = extractCardProps(linkState.details.data, linkState.details.meta, {
33
34
  featureFlags,
34
35
  handleInvoke: opts => linkActions.invoke(opts, appearance),
35
- handleAnalytics: analyticsHandler,
36
+ analytics: linkAnalytics,
37
+ origin,
36
38
  extensionKey: getExtensionKey(linkState.details),
37
39
  source: appearance
38
40
  }, undefined, platform);
@@ -47,6 +49,6 @@ export function useSmartLinkActions({
47
49
  invoke: action.promise
48
50
  }));
49
51
  setActions(cardActions);
50
- }, [linkState, linkActions, analyticsHandler, appearance, platform, embedModalSize]);
52
+ }, [linkState, linkActions, linkAnalytics, appearance, platform, embedModalSize, origin]);
51
53
  return actions;
52
54
  }