Commit 292fd91d authored by Samantha Ming's avatar Samantha Ming

Add click metric for security training link

This adds tracking to capture the click of the security training link
on the vulnerablity details page.
parent 09e1ddaa
...@@ -5,6 +5,7 @@ import { s__, __ } from '~/locale'; ...@@ -5,6 +5,7 @@ import { s__, __ } from '~/locale';
import securityTrainingProvidersQuery from '~/security_configuration/graphql/security_training_providers.query.graphql'; import securityTrainingProvidersQuery from '~/security_configuration/graphql/security_training_providers.query.graphql';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import Tracking from '~/tracking';
import { SUPPORTED_IDENTIFIER_TYPES } from '../constants'; import { SUPPORTED_IDENTIFIER_TYPES } from '../constants';
export const i18n = { export const i18n = {
...@@ -29,7 +30,7 @@ export default { ...@@ -29,7 +30,7 @@ export default {
GlIcon, GlIcon,
GlSkeletonLoader, GlSkeletonLoader,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin(), Tracking.mixin()],
inject: ['projectFullPath'], inject: ['projectFullPath'],
props: { props: {
identifiers: { identifiers: {
...@@ -111,6 +112,17 @@ export default { ...@@ -111,6 +112,17 @@ export default {
this.isLoading = false; this.isLoading = false;
} }
}, },
clickTrainingLink() {
const { name } = this.supportedIdentifier;
const { id } = mockProvider;
// Follow-up: switch to utilize constants once another MR is merged
// https://gitlab.com/gitlab-org/gitlab/-/issues/352915
this.track('click_security_training_link', {
label: `vendor_${id}`,
property: name,
});
},
}, },
}; };
</script> </script>
...@@ -129,7 +141,7 @@ export default { ...@@ -129,7 +141,7 @@ export default {
</div> </div>
<div v-else> <div v-else>
<div class="gl-font-weight-bold gl-font-base">{{ training.name }}</div> <div class="gl-font-weight-bold gl-font-base">{{ training.name }}</div>
<gl-link :href="training.url" target="_blank"> <gl-link :href="training.url" target="_blank" @click="clickTrainingLink">
{{ $options.i18n.viewTraining }} {{ $options.i18n.viewTraining }}
<gl-icon class="gl-ml-2" name="external-link" :size="12" /> <gl-icon class="gl-ml-2" name="external-link" :size="12" />
</gl-link> </gl-link>
......
...@@ -5,6 +5,7 @@ import * as Sentry from '@sentry/browser'; ...@@ -5,6 +5,7 @@ import * as Sentry from '@sentry/browser';
import { GlLink, GlIcon, GlSkeletonLoader } from '@gitlab/ui'; import { GlLink, GlIcon, GlSkeletonLoader } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status'; import httpStatus from '~/lib/utils/http_status';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import VulnerabilityTraining, { import VulnerabilityTraining, {
i18n, i18n,
...@@ -18,7 +19,10 @@ import waitForPromises from 'helpers/wait_for_promises'; ...@@ -18,7 +19,10 @@ import waitForPromises from 'helpers/wait_for_promises';
import { securityTrainingProvidersResponse } from 'jest/security_configuration/mock_data'; import { securityTrainingProvidersResponse } from 'jest/security_configuration/mock_data';
const defaultProps = { const defaultProps = {
identifiers: [{ externalType: SUPPORTED_IDENTIFIER_TYPES.cwe }, { externalType: 'cve' }], identifiers: [
{ externalType: SUPPORTED_IDENTIFIER_TYPES.cwe, name: 'CWE-81' },
{ externalType: 'cve' },
],
}; };
const mockSuccessTrainingUrl = 'training/path'; const mockSuccessTrainingUrl = 'training/path';
...@@ -179,6 +183,29 @@ describe('VulnerabilityTraining component', () => { ...@@ -179,6 +183,29 @@ describe('VulnerabilityTraining component', () => {
}); });
}); });
describe('metrics', () => {
let trackingSpy;
afterEach(() => {
unmockTracking();
});
it('tracks when a training link gets clicked', async () => {
await mockTrainingSuccess();
createComponent();
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
await waitForQueryToBeLoaded();
await findTrainingItemLink().vm.$emit('click');
// Follow-up: switch to utilize constants once another MR is merged
// https://gitlab.com/gitlab-org/gitlab/-/issues/352915
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_security_training_link', {
property: defaultProps.identifiers[0].name,
label: `vendor_${mockProvider.id}`,
});
});
});
describe('when secureVulnerabilityTraining feature flag is disabled', () => { describe('when secureVulnerabilityTraining feature flag is disabled', () => {
it('does not render the VulnerabilityTraining component', () => { it('does not render the VulnerabilityTraining component', () => {
createComponent({}, { secureVulnerabilityTraining: false }); createComponent({}, { secureVulnerabilityTraining: false });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment