debian-mirror-gitlab/app/assets/javascripts/design_management/utils/tracking.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import Api from '~/api';
2021-03-11 19:13:27 +05:30
import Tracking from '~/tracking';
2020-05-24 23:13:21 +05:30
2021-02-22 17:27:13 +05:30
// Snowplow tracking constants
2021-01-03 14:25:43 +05:30
const DESIGN_TRACKING_CONTEXT_SCHEMAS = {
VIEW_DESIGN_SCHEMA: 'iglu:com.gitlab/design_management_context/jsonschema/1-0-0',
};
2021-02-22 17:27:13 +05:30
export const DESIGN_TRACKING_PAGE_NAME = 'projects:issues:design';
export const DESIGN_SNOWPLOW_EVENT_TYPES = {
2021-01-03 14:25:43 +05:30
VIEW_DESIGN: 'view_design',
CREATE_DESIGN: 'create_design',
UPDATE_DESIGN: 'update_design',
};
2021-09-30 23:02:18 +05:30
export const DESIGN_SERVICE_PING_EVENT_TYPES = {
2021-02-22 17:27:13 +05:30
DESIGN_ACTION: 'design_action',
};
2020-05-24 23:13:21 +05:30
2021-02-22 17:27:13 +05:30
/**
* Track "design detail" view in Snowplow
*/
2020-05-24 23:13:21 +05:30
export function trackDesignDetailView(
referer = '',
owner = '',
designVersion = 1,
latestVersion = false,
) {
2021-02-22 17:27:13 +05:30
const eventName = DESIGN_SNOWPLOW_EVENT_TYPES.VIEW_DESIGN;
2021-01-03 14:25:43 +05:30
Tracking.event(DESIGN_TRACKING_PAGE_NAME, eventName, {
label: eventName,
2020-07-28 23:09:34 +05:30
context: {
2021-01-03 14:25:43 +05:30
schema: DESIGN_TRACKING_CONTEXT_SCHEMAS.VIEW_DESIGN_SCHEMA,
2020-07-28 23:09:34 +05:30
data: {
'design-version-number': designVersion,
'design-is-current-version': latestVersion,
'internal-object-referrer': referer,
'design-collection-owner': owner,
},
},
2020-05-24 23:13:21 +05:30
});
}
2021-01-03 14:25:43 +05:30
export function trackDesignCreate() {
2021-02-22 17:27:13 +05:30
return Tracking.event(DESIGN_TRACKING_PAGE_NAME, DESIGN_SNOWPLOW_EVENT_TYPES.CREATE_DESIGN);
2021-01-03 14:25:43 +05:30
}
export function trackDesignUpdate() {
2021-02-22 17:27:13 +05:30
return Tracking.event(DESIGN_TRACKING_PAGE_NAME, DESIGN_SNOWPLOW_EVENT_TYPES.UPDATE_DESIGN);
}
/**
2021-09-30 23:02:18 +05:30
* Track "design detail" view via service ping
2021-02-22 17:27:13 +05:30
*/
2021-09-30 23:02:18 +05:30
export function servicePingDesignDetailView() {
Api.trackRedisHllUserEvent(DESIGN_SERVICE_PING_EVENT_TYPES.DESIGN_ACTION);
2021-01-03 14:25:43 +05:30
}