@atlaskit/rovo-agent-analytics 0.4.0 → 0.6.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 (39) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/actions/package.json +17 -0
  3. package/create/package.json +17 -0
  4. package/dist/cjs/actions/index.js +70 -0
  5. package/dist/cjs/common/constants.js +9 -0
  6. package/dist/cjs/common/csid/index.js +55 -0
  7. package/dist/cjs/common/types.js +1 -0
  8. package/dist/cjs/common/utils/index.js +24 -0
  9. package/dist/cjs/create/index.js +71 -0
  10. package/dist/cjs/index.js +7 -0
  11. package/dist/es2019/actions/index.js +68 -0
  12. package/dist/es2019/common/constants.js +3 -0
  13. package/dist/es2019/common/csid/index.js +44 -0
  14. package/dist/es2019/common/types.js +0 -0
  15. package/dist/es2019/common/utils/index.js +15 -0
  16. package/dist/es2019/create/index.js +65 -0
  17. package/dist/es2019/index.js +1 -0
  18. package/dist/esm/actions/index.js +63 -0
  19. package/dist/esm/common/constants.js +3 -0
  20. package/dist/esm/common/csid/index.js +48 -0
  21. package/dist/esm/common/types.js +0 -0
  22. package/dist/esm/common/utils/index.js +17 -0
  23. package/dist/esm/create/index.js +64 -0
  24. package/dist/esm/index.js +1 -0
  25. package/dist/types/actions/index.d.ts +23 -0
  26. package/dist/types/common/constants.d.ts +3 -0
  27. package/dist/types/common/csid/index.d.ts +8 -0
  28. package/dist/types/common/types.d.ts +1 -0
  29. package/dist/types/common/utils/index.d.ts +5 -0
  30. package/dist/types/create/index.d.ts +16 -0
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types-ts4.5/actions/index.d.ts +23 -0
  33. package/dist/types-ts4.5/common/constants.d.ts +3 -0
  34. package/dist/types-ts4.5/common/csid/index.d.ts +11 -0
  35. package/dist/types-ts4.5/common/types.d.ts +1 -0
  36. package/dist/types-ts4.5/common/utils/index.d.ts +5 -0
  37. package/dist/types-ts4.5/create/index.d.ts +19 -0
  38. package/dist/types-ts4.5/index.d.ts +1 -0
  39. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/rovo-agent-analytics
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`83339258ea2e8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/83339258ea2e8) -
8
+ Update rovo agent analytics context
9
+
10
+ ## 0.5.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`93bff15d188d5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/93bff15d188d5) -
15
+ Update agent analytics create actions
16
+
3
17
  ## 0.4.0
4
18
 
5
19
  ### Minor Changes
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@atlaskit/rovo-agent-analytics/actions",
3
+ "main": "../dist/cjs/actions/index.js",
4
+ "module": "../dist/esm/actions/index.js",
5
+ "module:es2019": "../dist/es2019/actions/index.js",
6
+ "sideEffects": [
7
+ "*.compiled.css"
8
+ ],
9
+ "types": "../dist/types/actions/index.d.ts",
10
+ "typesVersions": {
11
+ ">=4.5 <5.9": {
12
+ "*": [
13
+ "../dist/types-ts4.5/actions/index.d.ts"
14
+ ]
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@atlaskit/rovo-agent-analytics/create",
3
+ "main": "../dist/cjs/create/index.js",
4
+ "module": "../dist/esm/create/index.js",
5
+ "module:es2019": "../dist/es2019/create/index.js",
6
+ "sideEffects": [
7
+ "*.compiled.css"
8
+ ],
9
+ "types": "../dist/types/create/index.d.ts",
10
+ "typesVersions": {
11
+ ">=4.5 <5.9": {
12
+ "*": [
13
+ "../dist/types-ts4.5/create/index.d.ts"
14
+ ]
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useRovoAgentActionAnalytics = exports.AgentActions = exports.ANALYTICS_CHANNEL = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _react = require("react");
10
+ var _analyticsListeners = require("@atlaskit/analytics-listeners");
11
+ var _analyticsNext = require("@atlaskit/analytics-next");
12
+ var _utils = require("../common/utils");
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ var AgentActions = exports.AgentActions = /*#__PURE__*/function (AgentActions) {
16
+ /* View agent clicked */
17
+ AgentActions["VIEW"] = "view";
18
+ /* Edit agent clicked */
19
+ AgentActions["EDIT"] = "edit";
20
+ /* Create agent clicked */
21
+ AgentActions["CREATE"] = "create";
22
+ /* Agent updated */
23
+ AgentActions["UPDATED"] = "updated";
24
+ /* Copy link clicked */
25
+ AgentActions["COPY_LINK"] = "copyLink";
26
+ /* Delete agent clicked */
27
+ AgentActions["DELETE"] = "delete";
28
+ /* Duplicate agent clicked */
29
+ AgentActions["DUPLICATE"] = "duplicate";
30
+ /* Star agent clicked */
31
+ AgentActions["STAR"] = "star";
32
+ /* Chat with agent clicked */
33
+ AgentActions["CHAT"] = "chat";
34
+ return AgentActions;
35
+ }({});
36
+ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = _analyticsListeners.FabricChannel.aiMate;
37
+ var useRovoAgentActionAnalytics = exports.useRovoAgentActionAnalytics = function useRovoAgentActionAnalytics(commonAttributes) {
38
+ var analyticsContext = (0, _react.useContext)(_analyticsNext.AnalyticsReactContext);
39
+ var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
40
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
41
+ var eventConfig = (0, _utils.getDefaultTrackEventConfig)();
42
+ var fireAnalyticsEvent = (0, _react.useCallback)(function (event) {
43
+ var attributes = _objectSpread(_objectSpread(_objectSpread({}, (0, _utils.getAttributesFromContexts)(analyticsContext.getAtlaskitAnalyticsContext())), commonAttributes), event.attributes);
44
+ createAnalyticsEvent(_objectSpread(_objectSpread(_objectSpread({}, eventConfig), event), {}, {
45
+ attributes: attributes
46
+ })).fire(ANALYTICS_CHANNEL);
47
+ }, [createAnalyticsEvent, eventConfig, commonAttributes, analyticsContext]);
48
+ var trackAgentAction = (0, _react.useCallback)(function (action, attributes) {
49
+ fireAnalyticsEvent({
50
+ actionSubject: 'rovoAgent',
51
+ action: action,
52
+ attributes: attributes
53
+ });
54
+ }, [fireAnalyticsEvent]);
55
+ var trackAgentActionError = (0, _react.useCallback)(function (action, error, attributes) {
56
+ fireAnalyticsEvent({
57
+ actionSubject: 'rovoAgentError',
58
+ action: action,
59
+ attributes: _objectSpread(_objectSpread({}, attributes), {}, {
60
+ error: {
61
+ message: error.message
62
+ }
63
+ })
64
+ });
65
+ }, [fireAnalyticsEvent]);
66
+ return {
67
+ trackAgentAction: trackAgentAction,
68
+ trackAgentActionError: trackAgentActionError
69
+ };
70
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CSID_QUERY_PARAM = exports.ANALYTICS_CHANNEL = void 0;
7
+ var _analyticsListeners = require("@atlaskit/analytics-listeners");
8
+ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = _analyticsListeners.FabricChannel.aiMate;
9
+ var CSID_QUERY_PARAM = exports.CSID_QUERY_PARAM = 'csid';
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useRovoAgentCSID = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _constants = require("../constants");
11
+ var CACHED_CSID = null;
12
+ var generateCSID = function generateCSID() {
13
+ return crypto.randomUUID();
14
+ };
15
+ var retrieveCSID = function retrieveCSID() {
16
+ if (CACHED_CSID) {
17
+ return CACHED_CSID;
18
+ }
19
+ var queryParams = new URLSearchParams(window.location.search);
20
+ var querySessionId = queryParams.get(_constants.CSID_QUERY_PARAM);
21
+ return querySessionId !== null && querySessionId !== void 0 ? querySessionId : generateCSID();
22
+ };
23
+
24
+ /**
25
+ * Hook to get Rovo Agent Create Session ID (CSID) from the query parameters or generate a new one if not found.
26
+ * @returns Rovo Agent CSID as a string.
27
+ */
28
+ var useRovoAgentCSID = exports.useRovoAgentCSID = function useRovoAgentCSID() {
29
+ var _useState = (0, _react.useState)(retrieveCSID()),
30
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
31
+ CSID = _useState2[0],
32
+ setCSID = _useState2[1];
33
+ var actions = (0, _react.useMemo)(function () {
34
+ return {
35
+ refresh: function refresh() {
36
+ var newCSID = generateCSID();
37
+ setCSID(newCSID);
38
+ },
39
+ clear: function clear() {
40
+ // remove CSID query parameter
41
+ var url = new URL(window.location.href);
42
+ url.searchParams.delete(_constants.CSID_QUERY_PARAM);
43
+ window.history.replaceState({}, '', url.toString());
44
+
45
+ // reset state
46
+ setCSID(null);
47
+ }
48
+ };
49
+ }, []);
50
+ (0, _react.useEffect)(function () {
51
+ // sync cache on state change
52
+ CACHED_CSID = CSID;
53
+ }, [CSID]);
54
+ return [CSID, actions];
55
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getDefaultTrackEventConfig = exports.getAttributesFromContexts = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ var getDefaultTrackEventConfig = exports.getDefaultTrackEventConfig = function getDefaultTrackEventConfig() {
12
+ return {
13
+ eventType: 'track',
14
+ tags: ['atlaskit']
15
+ };
16
+ };
17
+ var getAttributesFromContexts = exports.getAttributesFromContexts = function getAttributesFromContexts(context) {
18
+ if (!context || !Array.isArray(context)) {
19
+ return {};
20
+ }
21
+ return context.reduce(function (acc, x) {
22
+ return _objectSpread(_objectSpread({}, acc), x);
23
+ }, {});
24
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useRovoAgentCreateAnalytics = exports.AgentCreateActions = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = require("react");
11
+ var _analyticsNext = require("@atlaskit/analytics-next");
12
+ var _constants = require("../common/constants");
13
+ var _csid = require("../common/csid");
14
+ var _utils = require("../common/utils");
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ var AgentCreateActions = exports.AgentCreateActions = /*#__PURE__*/function (AgentCreateActions) {
18
+ AgentCreateActions["START"] = "createFlowStart";
19
+ AgentCreateActions["SKIP_NL"] = "createFlowSkipNL";
20
+ AgentCreateActions["REVIEW_NL"] = "createFlowReviewNL";
21
+ AgentCreateActions["ACTIVATE"] = "createFlowActivate";
22
+ AgentCreateActions["ERROR"] = "createFlowError";
23
+ return AgentCreateActions;
24
+ }({});
25
+ var useRovoAgentCreateAnalytics = exports.useRovoAgentCreateAnalytics = function useRovoAgentCreateAnalytics(commonAttributes) {
26
+ var _useRovoAgentCSID = (0, _csid.useRovoAgentCSID)(),
27
+ _useRovoAgentCSID2 = (0, _slicedToArray2.default)(_useRovoAgentCSID, 2),
28
+ csid = _useRovoAgentCSID2[0],
29
+ refreshCSID = _useRovoAgentCSID2[1].refresh;
30
+ var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
31
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
32
+ var eventConfig = (0, _utils.getDefaultTrackEventConfig)();
33
+ var fireAnalyticsEvent = (0, _react.useCallback)(function (event) {
34
+ createAnalyticsEvent(_objectSpread(_objectSpread(_objectSpread({}, eventConfig), event), {}, {
35
+ attributes: _objectSpread(_objectSpread({
36
+ csid: csid
37
+ }, commonAttributes), event.attributes)
38
+ })).fire(_constants.ANALYTICS_CHANNEL);
39
+ }, [createAnalyticsEvent, eventConfig, csid, commonAttributes]);
40
+ var trackCreateSession = (0, _react.useCallback)(function (action, attributes) {
41
+ fireAnalyticsEvent({
42
+ actionSubject: 'rovoAgent',
43
+ action: action,
44
+ attributes: attributes
45
+ });
46
+ }, [fireAnalyticsEvent]);
47
+ var trackCreateSessionStart = (0, _react.useCallback)(function (attributes) {
48
+ fireAnalyticsEvent({
49
+ actionSubject: 'rovoAgent',
50
+ action: AgentCreateActions.START,
51
+ attributes: attributes
52
+ });
53
+ refreshCSID();
54
+ }, [fireAnalyticsEvent, refreshCSID]);
55
+ var trackCreateSessionError = (0, _react.useCallback)(function (error, attributes) {
56
+ fireAnalyticsEvent({
57
+ actionSubject: 'rovoAgent',
58
+ action: AgentCreateActions.ERROR,
59
+ attributes: _objectSpread({
60
+ error: {
61
+ message: error.message
62
+ }
63
+ }, attributes)
64
+ });
65
+ }, [fireAnalyticsEvent]);
66
+ return [csid, {
67
+ trackCreateSession: trackCreateSession,
68
+ trackCreateSessionStart: trackCreateSessionStart,
69
+ trackCreateSessionError: trackCreateSessionError
70
+ }];
71
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useRovoAgentActionAnalytics = void 0;
7
+ var useRovoAgentActionAnalytics = exports.useRovoAgentActionAnalytics = function useRovoAgentActionAnalytics() {};
@@ -0,0 +1,68 @@
1
+ import { useCallback, useContext } from 'react';
2
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
3
+ import { AnalyticsReactContext, useAnalyticsEvents } from '@atlaskit/analytics-next';
4
+ import { getAttributesFromContexts, getDefaultTrackEventConfig } from '../common/utils';
5
+ export let AgentActions = /*#__PURE__*/function (AgentActions) {
6
+ /* View agent clicked */
7
+ AgentActions["VIEW"] = "view";
8
+ /* Edit agent clicked */
9
+ AgentActions["EDIT"] = "edit";
10
+ /* Create agent clicked */
11
+ AgentActions["CREATE"] = "create";
12
+ /* Agent updated */
13
+ AgentActions["UPDATED"] = "updated";
14
+ /* Copy link clicked */
15
+ AgentActions["COPY_LINK"] = "copyLink";
16
+ /* Delete agent clicked */
17
+ AgentActions["DELETE"] = "delete";
18
+ /* Duplicate agent clicked */
19
+ AgentActions["DUPLICATE"] = "duplicate";
20
+ /* Star agent clicked */
21
+ AgentActions["STAR"] = "star";
22
+ /* Chat with agent clicked */
23
+ AgentActions["CHAT"] = "chat";
24
+ return AgentActions;
25
+ }({});
26
+ export const ANALYTICS_CHANNEL = FabricChannel.aiMate;
27
+ export const useRovoAgentActionAnalytics = commonAttributes => {
28
+ const analyticsContext = useContext(AnalyticsReactContext);
29
+ const {
30
+ createAnalyticsEvent
31
+ } = useAnalyticsEvents();
32
+ const eventConfig = getDefaultTrackEventConfig();
33
+ const fireAnalyticsEvent = useCallback(event => {
34
+ const attributes = {
35
+ ...getAttributesFromContexts(analyticsContext.getAtlaskitAnalyticsContext()),
36
+ ...commonAttributes,
37
+ ...event.attributes
38
+ };
39
+ createAnalyticsEvent({
40
+ ...eventConfig,
41
+ ...event,
42
+ attributes
43
+ }).fire(ANALYTICS_CHANNEL);
44
+ }, [createAnalyticsEvent, eventConfig, commonAttributes, analyticsContext]);
45
+ const trackAgentAction = useCallback((action, attributes) => {
46
+ fireAnalyticsEvent({
47
+ actionSubject: 'rovoAgent',
48
+ action,
49
+ attributes
50
+ });
51
+ }, [fireAnalyticsEvent]);
52
+ const trackAgentActionError = useCallback((action, error, attributes) => {
53
+ fireAnalyticsEvent({
54
+ actionSubject: 'rovoAgentError',
55
+ action,
56
+ attributes: {
57
+ ...attributes,
58
+ error: {
59
+ message: error.message
60
+ }
61
+ }
62
+ });
63
+ }, [fireAnalyticsEvent]);
64
+ return {
65
+ trackAgentAction,
66
+ trackAgentActionError
67
+ };
68
+ };
@@ -0,0 +1,3 @@
1
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
2
+ export const ANALYTICS_CHANNEL = FabricChannel.aiMate;
3
+ export const CSID_QUERY_PARAM = 'csid';
@@ -0,0 +1,44 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { CSID_QUERY_PARAM } from '../constants';
3
+ let CACHED_CSID = null;
4
+ const generateCSID = () => {
5
+ return crypto.randomUUID();
6
+ };
7
+ const retrieveCSID = () => {
8
+ if (CACHED_CSID) {
9
+ return CACHED_CSID;
10
+ }
11
+ const queryParams = new URLSearchParams(window.location.search);
12
+ const querySessionId = queryParams.get(CSID_QUERY_PARAM);
13
+ return querySessionId !== null && querySessionId !== void 0 ? querySessionId : generateCSID();
14
+ };
15
+
16
+ /**
17
+ * Hook to get Rovo Agent Create Session ID (CSID) from the query parameters or generate a new one if not found.
18
+ * @returns Rovo Agent CSID as a string.
19
+ */
20
+ export const useRovoAgentCSID = () => {
21
+ const [CSID, setCSID] = useState(retrieveCSID());
22
+ const actions = useMemo(() => {
23
+ return {
24
+ refresh: () => {
25
+ const newCSID = generateCSID();
26
+ setCSID(newCSID);
27
+ },
28
+ clear: () => {
29
+ // remove CSID query parameter
30
+ const url = new URL(window.location.href);
31
+ url.searchParams.delete(CSID_QUERY_PARAM);
32
+ window.history.replaceState({}, '', url.toString());
33
+
34
+ // reset state
35
+ setCSID(null);
36
+ }
37
+ };
38
+ }, []);
39
+ useEffect(() => {
40
+ // sync cache on state change
41
+ CACHED_CSID = CSID;
42
+ }, [CSID]);
43
+ return [CSID, actions];
44
+ };
File without changes
@@ -0,0 +1,15 @@
1
+ export const getDefaultTrackEventConfig = () => ({
2
+ eventType: 'track',
3
+ tags: ['atlaskit']
4
+ });
5
+ export const getAttributesFromContexts = context => {
6
+ if (!context || !Array.isArray(context)) {
7
+ return {};
8
+ }
9
+ return context.reduce((acc, x) => {
10
+ return {
11
+ ...acc,
12
+ ...x
13
+ };
14
+ }, {});
15
+ };
@@ -0,0 +1,65 @@
1
+ import { useCallback } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
+ import { ANALYTICS_CHANNEL } from '../common/constants';
4
+ import { useRovoAgentCSID } from '../common/csid';
5
+ import { getDefaultTrackEventConfig } from '../common/utils';
6
+ export let AgentCreateActions = /*#__PURE__*/function (AgentCreateActions) {
7
+ AgentCreateActions["START"] = "createFlowStart";
8
+ AgentCreateActions["SKIP_NL"] = "createFlowSkipNL";
9
+ AgentCreateActions["REVIEW_NL"] = "createFlowReviewNL";
10
+ AgentCreateActions["ACTIVATE"] = "createFlowActivate";
11
+ AgentCreateActions["ERROR"] = "createFlowError";
12
+ return AgentCreateActions;
13
+ }({});
14
+ export const useRovoAgentCreateAnalytics = commonAttributes => {
15
+ const [csid, {
16
+ refresh: refreshCSID
17
+ }] = useRovoAgentCSID();
18
+ const {
19
+ createAnalyticsEvent
20
+ } = useAnalyticsEvents();
21
+ const eventConfig = getDefaultTrackEventConfig();
22
+ const fireAnalyticsEvent = useCallback(event => {
23
+ createAnalyticsEvent({
24
+ ...eventConfig,
25
+ ...event,
26
+ attributes: {
27
+ csid,
28
+ ...commonAttributes,
29
+ ...event.attributes
30
+ }
31
+ }).fire(ANALYTICS_CHANNEL);
32
+ }, [createAnalyticsEvent, eventConfig, csid, commonAttributes]);
33
+ const trackCreateSession = useCallback((action, attributes) => {
34
+ fireAnalyticsEvent({
35
+ actionSubject: 'rovoAgent',
36
+ action,
37
+ attributes
38
+ });
39
+ }, [fireAnalyticsEvent]);
40
+ const trackCreateSessionStart = useCallback(attributes => {
41
+ fireAnalyticsEvent({
42
+ actionSubject: 'rovoAgent',
43
+ action: AgentCreateActions.START,
44
+ attributes
45
+ });
46
+ refreshCSID();
47
+ }, [fireAnalyticsEvent, refreshCSID]);
48
+ const trackCreateSessionError = useCallback((error, attributes) => {
49
+ fireAnalyticsEvent({
50
+ actionSubject: 'rovoAgent',
51
+ action: AgentCreateActions.ERROR,
52
+ attributes: {
53
+ error: {
54
+ message: error.message
55
+ },
56
+ ...attributes
57
+ }
58
+ });
59
+ }, [fireAnalyticsEvent]);
60
+ return [csid, {
61
+ trackCreateSession,
62
+ trackCreateSessionStart,
63
+ trackCreateSessionError
64
+ }];
65
+ };
@@ -0,0 +1 @@
1
+ export const useRovoAgentActionAnalytics = () => {};
@@ -0,0 +1,63 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { useCallback, useContext } from 'react';
5
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
6
+ import { AnalyticsReactContext, useAnalyticsEvents } from '@atlaskit/analytics-next';
7
+ import { getAttributesFromContexts, getDefaultTrackEventConfig } from '../common/utils';
8
+ export var AgentActions = /*#__PURE__*/function (AgentActions) {
9
+ /* View agent clicked */
10
+ AgentActions["VIEW"] = "view";
11
+ /* Edit agent clicked */
12
+ AgentActions["EDIT"] = "edit";
13
+ /* Create agent clicked */
14
+ AgentActions["CREATE"] = "create";
15
+ /* Agent updated */
16
+ AgentActions["UPDATED"] = "updated";
17
+ /* Copy link clicked */
18
+ AgentActions["COPY_LINK"] = "copyLink";
19
+ /* Delete agent clicked */
20
+ AgentActions["DELETE"] = "delete";
21
+ /* Duplicate agent clicked */
22
+ AgentActions["DUPLICATE"] = "duplicate";
23
+ /* Star agent clicked */
24
+ AgentActions["STAR"] = "star";
25
+ /* Chat with agent clicked */
26
+ AgentActions["CHAT"] = "chat";
27
+ return AgentActions;
28
+ }({});
29
+ export var ANALYTICS_CHANNEL = FabricChannel.aiMate;
30
+ export var useRovoAgentActionAnalytics = function useRovoAgentActionAnalytics(commonAttributes) {
31
+ var analyticsContext = useContext(AnalyticsReactContext);
32
+ var _useAnalyticsEvents = useAnalyticsEvents(),
33
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
34
+ var eventConfig = getDefaultTrackEventConfig();
35
+ var fireAnalyticsEvent = useCallback(function (event) {
36
+ var attributes = _objectSpread(_objectSpread(_objectSpread({}, getAttributesFromContexts(analyticsContext.getAtlaskitAnalyticsContext())), commonAttributes), event.attributes);
37
+ createAnalyticsEvent(_objectSpread(_objectSpread(_objectSpread({}, eventConfig), event), {}, {
38
+ attributes: attributes
39
+ })).fire(ANALYTICS_CHANNEL);
40
+ }, [createAnalyticsEvent, eventConfig, commonAttributes, analyticsContext]);
41
+ var trackAgentAction = useCallback(function (action, attributes) {
42
+ fireAnalyticsEvent({
43
+ actionSubject: 'rovoAgent',
44
+ action: action,
45
+ attributes: attributes
46
+ });
47
+ }, [fireAnalyticsEvent]);
48
+ var trackAgentActionError = useCallback(function (action, error, attributes) {
49
+ fireAnalyticsEvent({
50
+ actionSubject: 'rovoAgentError',
51
+ action: action,
52
+ attributes: _objectSpread(_objectSpread({}, attributes), {}, {
53
+ error: {
54
+ message: error.message
55
+ }
56
+ })
57
+ });
58
+ }, [fireAnalyticsEvent]);
59
+ return {
60
+ trackAgentAction: trackAgentAction,
61
+ trackAgentActionError: trackAgentActionError
62
+ };
63
+ };
@@ -0,0 +1,3 @@
1
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
2
+ export var ANALYTICS_CHANNEL = FabricChannel.aiMate;
3
+ export var CSID_QUERY_PARAM = 'csid';
@@ -0,0 +1,48 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useEffect, useMemo, useState } from 'react';
3
+ import { CSID_QUERY_PARAM } from '../constants';
4
+ var CACHED_CSID = null;
5
+ var generateCSID = function generateCSID() {
6
+ return crypto.randomUUID();
7
+ };
8
+ var retrieveCSID = function retrieveCSID() {
9
+ if (CACHED_CSID) {
10
+ return CACHED_CSID;
11
+ }
12
+ var queryParams = new URLSearchParams(window.location.search);
13
+ var querySessionId = queryParams.get(CSID_QUERY_PARAM);
14
+ return querySessionId !== null && querySessionId !== void 0 ? querySessionId : generateCSID();
15
+ };
16
+
17
+ /**
18
+ * Hook to get Rovo Agent Create Session ID (CSID) from the query parameters or generate a new one if not found.
19
+ * @returns Rovo Agent CSID as a string.
20
+ */
21
+ export var useRovoAgentCSID = function useRovoAgentCSID() {
22
+ var _useState = useState(retrieveCSID()),
23
+ _useState2 = _slicedToArray(_useState, 2),
24
+ CSID = _useState2[0],
25
+ setCSID = _useState2[1];
26
+ var actions = useMemo(function () {
27
+ return {
28
+ refresh: function refresh() {
29
+ var newCSID = generateCSID();
30
+ setCSID(newCSID);
31
+ },
32
+ clear: function clear() {
33
+ // remove CSID query parameter
34
+ var url = new URL(window.location.href);
35
+ url.searchParams.delete(CSID_QUERY_PARAM);
36
+ window.history.replaceState({}, '', url.toString());
37
+
38
+ // reset state
39
+ setCSID(null);
40
+ }
41
+ };
42
+ }, []);
43
+ useEffect(function () {
44
+ // sync cache on state change
45
+ CACHED_CSID = CSID;
46
+ }, [CSID]);
47
+ return [CSID, actions];
48
+ };
File without changes
@@ -0,0 +1,17 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ export var getDefaultTrackEventConfig = function getDefaultTrackEventConfig() {
5
+ return {
6
+ eventType: 'track',
7
+ tags: ['atlaskit']
8
+ };
9
+ };
10
+ export var getAttributesFromContexts = function getAttributesFromContexts(context) {
11
+ if (!context || !Array.isArray(context)) {
12
+ return {};
13
+ }
14
+ return context.reduce(function (acc, x) {
15
+ return _objectSpread(_objectSpread({}, acc), x);
16
+ }, {});
17
+ };
@@ -0,0 +1,64 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ import { useCallback } from 'react';
6
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
7
+ import { ANALYTICS_CHANNEL } from '../common/constants';
8
+ import { useRovoAgentCSID } from '../common/csid';
9
+ import { getDefaultTrackEventConfig } from '../common/utils';
10
+ export var AgentCreateActions = /*#__PURE__*/function (AgentCreateActions) {
11
+ AgentCreateActions["START"] = "createFlowStart";
12
+ AgentCreateActions["SKIP_NL"] = "createFlowSkipNL";
13
+ AgentCreateActions["REVIEW_NL"] = "createFlowReviewNL";
14
+ AgentCreateActions["ACTIVATE"] = "createFlowActivate";
15
+ AgentCreateActions["ERROR"] = "createFlowError";
16
+ return AgentCreateActions;
17
+ }({});
18
+ export var useRovoAgentCreateAnalytics = function useRovoAgentCreateAnalytics(commonAttributes) {
19
+ var _useRovoAgentCSID = useRovoAgentCSID(),
20
+ _useRovoAgentCSID2 = _slicedToArray(_useRovoAgentCSID, 2),
21
+ csid = _useRovoAgentCSID2[0],
22
+ refreshCSID = _useRovoAgentCSID2[1].refresh;
23
+ var _useAnalyticsEvents = useAnalyticsEvents(),
24
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
25
+ var eventConfig = getDefaultTrackEventConfig();
26
+ var fireAnalyticsEvent = useCallback(function (event) {
27
+ createAnalyticsEvent(_objectSpread(_objectSpread(_objectSpread({}, eventConfig), event), {}, {
28
+ attributes: _objectSpread(_objectSpread({
29
+ csid: csid
30
+ }, commonAttributes), event.attributes)
31
+ })).fire(ANALYTICS_CHANNEL);
32
+ }, [createAnalyticsEvent, eventConfig, csid, commonAttributes]);
33
+ var trackCreateSession = useCallback(function (action, attributes) {
34
+ fireAnalyticsEvent({
35
+ actionSubject: 'rovoAgent',
36
+ action: action,
37
+ attributes: attributes
38
+ });
39
+ }, [fireAnalyticsEvent]);
40
+ var trackCreateSessionStart = useCallback(function (attributes) {
41
+ fireAnalyticsEvent({
42
+ actionSubject: 'rovoAgent',
43
+ action: AgentCreateActions.START,
44
+ attributes: attributes
45
+ });
46
+ refreshCSID();
47
+ }, [fireAnalyticsEvent, refreshCSID]);
48
+ var trackCreateSessionError = useCallback(function (error, attributes) {
49
+ fireAnalyticsEvent({
50
+ actionSubject: 'rovoAgent',
51
+ action: AgentCreateActions.ERROR,
52
+ attributes: _objectSpread({
53
+ error: {
54
+ message: error.message
55
+ }
56
+ }, attributes)
57
+ });
58
+ }, [fireAnalyticsEvent]);
59
+ return [csid, {
60
+ trackCreateSession: trackCreateSession,
61
+ trackCreateSessionStart: trackCreateSessionStart,
62
+ trackCreateSessionError: trackCreateSessionError
63
+ }];
64
+ };
@@ -0,0 +1 @@
1
+ export var useRovoAgentActionAnalytics = function useRovoAgentActionAnalytics() {};
@@ -0,0 +1,23 @@
1
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
2
+ import type { RemainingRequired } from '../common/types';
3
+ export declare enum AgentActions {
4
+ VIEW = "view",
5
+ EDIT = "edit",
6
+ CREATE = "create",
7
+ UPDATED = "updated",
8
+ COPY_LINK = "copyLink",
9
+ DELETE = "delete",
10
+ DUPLICATE = "duplicate",
11
+ STAR = "star",
12
+ CHAT = "chat"
13
+ }
14
+ type CommonAnalyticsAttributes = {
15
+ touchPoint: string;
16
+ agentId: string;
17
+ };
18
+ export declare const ANALYTICS_CHANNEL = FabricChannel.aiMate;
19
+ export declare const useRovoAgentActionAnalytics: <T extends Partial<CommonAnalyticsAttributes>>(commonAttributes: T) => {
20
+ trackAgentAction: (action: AgentActions, attributes: RemainingRequired<CommonAnalyticsAttributes, T> & Record<string, any>) => void;
21
+ trackAgentActionError: (action: AgentActions, error: Error, attributes?: RemainingRequired<CommonAnalyticsAttributes, T> & Record<string, any>) => void;
22
+ };
23
+ export {};
@@ -0,0 +1,3 @@
1
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
2
+ export declare const ANALYTICS_CHANNEL = FabricChannel.aiMate;
3
+ export declare const CSID_QUERY_PARAM = "csid";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Hook to get Rovo Agent Create Session ID (CSID) from the query parameters or generate a new one if not found.
3
+ * @returns Rovo Agent CSID as a string.
4
+ */
5
+ export declare const useRovoAgentCSID: () => readonly [string | null, {
6
+ refresh: () => void;
7
+ clear: () => void;
8
+ }];
@@ -0,0 +1 @@
1
+ export type RemainingRequired<T, P extends Partial<T>> = Required<Omit<T, keyof P>>;
@@ -0,0 +1,5 @@
1
+ export declare const getDefaultTrackEventConfig: () => {
2
+ eventType: string;
3
+ tags: string[];
4
+ };
5
+ export declare const getAttributesFromContexts: (context: unknown) => Record<string, any>;
@@ -0,0 +1,16 @@
1
+ type CommonAnalyticsAttributes = {
2
+ touchPoint?: string;
3
+ } & Record<string, any>;
4
+ export declare enum AgentCreateActions {
5
+ START = "createFlowStart",
6
+ SKIP_NL = "createFlowSkipNL",
7
+ REVIEW_NL = "createFlowReviewNL",
8
+ ACTIVATE = "createFlowActivate",
9
+ ERROR = "createFlowError"
10
+ }
11
+ export declare const useRovoAgentCreateAnalytics: (commonAttributes: CommonAnalyticsAttributes) => readonly [string | null, {
12
+ readonly trackCreateSession: (action: AgentCreateActions, attributes?: CommonAnalyticsAttributes) => void;
13
+ readonly trackCreateSessionStart: (attributes?: CommonAnalyticsAttributes) => void;
14
+ readonly trackCreateSessionError: (error: Error, attributes?: CommonAnalyticsAttributes) => void;
15
+ }];
16
+ export {};
@@ -0,0 +1 @@
1
+ export declare const useRovoAgentActionAnalytics: () => void;
@@ -0,0 +1,23 @@
1
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
2
+ import type { RemainingRequired } from '../common/types';
3
+ export declare enum AgentActions {
4
+ VIEW = "view",
5
+ EDIT = "edit",
6
+ CREATE = "create",
7
+ UPDATED = "updated",
8
+ COPY_LINK = "copyLink",
9
+ DELETE = "delete",
10
+ DUPLICATE = "duplicate",
11
+ STAR = "star",
12
+ CHAT = "chat"
13
+ }
14
+ type CommonAnalyticsAttributes = {
15
+ touchPoint: string;
16
+ agentId: string;
17
+ };
18
+ export declare const ANALYTICS_CHANNEL = FabricChannel.aiMate;
19
+ export declare const useRovoAgentActionAnalytics: <T extends Partial<CommonAnalyticsAttributes>>(commonAttributes: T) => {
20
+ trackAgentAction: (action: AgentActions, attributes: RemainingRequired<CommonAnalyticsAttributes, T> & Record<string, any>) => void;
21
+ trackAgentActionError: (action: AgentActions, error: Error, attributes?: RemainingRequired<CommonAnalyticsAttributes, T> & Record<string, any>) => void;
22
+ };
23
+ export {};
@@ -0,0 +1,3 @@
1
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
2
+ export declare const ANALYTICS_CHANNEL = FabricChannel.aiMate;
3
+ export declare const CSID_QUERY_PARAM = "csid";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Hook to get Rovo Agent Create Session ID (CSID) from the query parameters or generate a new one if not found.
3
+ * @returns Rovo Agent CSID as a string.
4
+ */
5
+ export declare const useRovoAgentCSID: () => readonly [
6
+ string | null,
7
+ {
8
+ refresh: () => void;
9
+ clear: () => void;
10
+ }
11
+ ];
@@ -0,0 +1 @@
1
+ export type RemainingRequired<T, P extends Partial<T>> = Required<Omit<T, keyof P>>;
@@ -0,0 +1,5 @@
1
+ export declare const getDefaultTrackEventConfig: () => {
2
+ eventType: string;
3
+ tags: string[];
4
+ };
5
+ export declare const getAttributesFromContexts: (context: unknown) => Record<string, any>;
@@ -0,0 +1,19 @@
1
+ type CommonAnalyticsAttributes = {
2
+ touchPoint?: string;
3
+ } & Record<string, any>;
4
+ export declare enum AgentCreateActions {
5
+ START = "createFlowStart",
6
+ SKIP_NL = "createFlowSkipNL",
7
+ REVIEW_NL = "createFlowReviewNL",
8
+ ACTIVATE = "createFlowActivate",
9
+ ERROR = "createFlowError"
10
+ }
11
+ export declare const useRovoAgentCreateAnalytics: (commonAttributes: CommonAnalyticsAttributes) => readonly [
12
+ string | null,
13
+ {
14
+ readonly trackCreateSession: (action: AgentCreateActions, attributes?: CommonAnalyticsAttributes) => void;
15
+ readonly trackCreateSessionStart: (attributes?: CommonAnalyticsAttributes) => void;
16
+ readonly trackCreateSessionError: (error: Error, attributes?: CommonAnalyticsAttributes) => void;
17
+ }
18
+ ];
19
+ export {};
@@ -0,0 +1 @@
1
+ export declare const useRovoAgentActionAnalytics: () => void;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "category": "Layout and structure"
7
7
  }
8
8
  },
9
- "repository": "https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo",
9
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend-monorepo",
10
10
  "main": "dist/cjs/index.js",
11
11
  "module": "dist/esm/index.js",
12
12
  "module:es2019": "dist/es2019/index.js",
@@ -83,7 +83,7 @@
83
83
  ]
84
84
  },
85
85
  "name": "@atlaskit/rovo-agent-analytics",
86
- "version": "0.4.0",
86
+ "version": "0.6.0",
87
87
  "description": "Rovo Agents analytics",
88
88
  "author": "Atlassian Pty Ltd",
89
89
  "license": "Apache-2.0",