Commit c4635817 authored by Jackie Fraser's avatar Jackie Fraser

Send event each time we show pipeline nudge 2

This is the view event for the second and third nudge
steps of the experiment.
parent 86509ce3
...@@ -4,6 +4,9 @@ import Cookies from 'js-cookie'; ...@@ -4,6 +4,9 @@ import Cookies from 'js-cookie';
import { parseBoolean, scrollToElement } from '~/lib/utils/common_utils'; import { parseBoolean, scrollToElement } from '~/lib/utils/common_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { glEmojiTag } from '~/emoji'; import { glEmojiTag } from '~/emoji';
import Tracking from '~/tracking';
const trackingMixin = Tracking.mixin();
const popoverStates = { const popoverStates = {
suggest_gitlab_ci_yml: { suggest_gitlab_ci_yml: {
...@@ -27,6 +30,7 @@ export default { ...@@ -27,6 +30,7 @@ export default {
GlIcon, GlIcon,
GlButton, GlButton,
}, },
mixins: [trackingMixin],
props: { props: {
target: { target: {
type: String, type: String,
...@@ -40,10 +44,18 @@ export default { ...@@ -40,10 +44,18 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
humanAccess: {
type: String,
required: true,
},
}, },
data() { data() {
return { return {
popoverDismissed: parseBoolean(Cookies.get(this.dismissKey)), popoverDismissed: parseBoolean(Cookies.get(this.dismissKey)),
tracking: {
label: this.trackLabel,
property: this.humanAccess,
},
}; };
}, },
computed: { computed: {
...@@ -60,12 +72,17 @@ export default { ...@@ -60,12 +72,17 @@ export default {
mounted() { mounted() {
if (this.trackLabel === 'suggest_commit_first_project_gitlab_ci_yml' && !this.popoverDismissed) if (this.trackLabel === 'suggest_commit_first_project_gitlab_ci_yml' && !this.popoverDismissed)
scrollToElement(document.querySelector(this.target)); scrollToElement(document.querySelector(this.target));
this.trackOnShow();
}, },
methods: { methods: {
onDismiss() { onDismiss() {
this.popoverDismissed = true; this.popoverDismissed = true;
Cookies.set(this.dismissKey, this.popoverDismissed, { expires: 365 }); Cookies.set(this.dismissKey, this.popoverDismissed, { expires: 365 });
}, },
trackOnShow() {
if (!this.popoverDismissed) this.track();
},
}, },
}; };
</script> </script>
......
...@@ -10,6 +10,7 @@ export default el => ...@@ -10,6 +10,7 @@ export default el =>
target: el.dataset.target, target: el.dataset.target,
trackLabel: el.dataset.trackLabel, trackLabel: el.dataset.trackLabel,
dismissKey: el.dataset.dismissKey, dismissKey: el.dataset.dismissKey,
humanAccess: el.dataset.humanAccess,
}, },
}); });
}, },
......
...@@ -353,4 +353,8 @@ module BlobHelper ...@@ -353,4 +353,8 @@ module BlobHelper
def suggest_pipeline_commit_cookie_name def suggest_pipeline_commit_cookie_name
"suggest_gitlab_ci_yml_commit_#{@project.id}" "suggest_gitlab_ci_yml_commit_#{@project.id}"
end end
def human_access
@project.team.human_max_access(current_user&.id).try(:downcase)
end
end end
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
.js-suggest-gitlab-ci-yml{ data: { toggle: 'popover', .js-suggest-gitlab-ci-yml{ data: { toggle: 'popover',
target: '#gitlab-ci-yml-selector', target: '#gitlab-ci-yml-selector',
track_label: 'suggest_gitlab_ci_yml', track_label: 'suggest_gitlab_ci_yml',
dismiss_key: "suggest_gitlab_ci_yml_#{@project.id}" } } dismiss_key: "suggest_gitlab_ci_yml_#{@project.id}",
human_access: human_access } }
.file-buttons .file-buttons
- if is_markdown - if is_markdown
......
...@@ -17,4 +17,5 @@ ...@@ -17,4 +17,5 @@
.js-suggest-gitlab-ci-yml-commit-changes{ data: { toggle: 'popover', .js-suggest-gitlab-ci-yml-commit-changes{ data: { toggle: 'popover',
target: '#commit-changes', target: '#commit-changes',
track_label: 'suggest_commit_first_project_gitlab_ci_yml', track_label: 'suggest_commit_first_project_gitlab_ci_yml',
dismiss_key: "suggest_commit_first_project_gitlab_ci_yml_#{@project.id}" } } dismiss_key: "suggest_commit_first_project_gitlab_ci_yml_#{@project.id}",
human_access: human_access } }
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Popover from '~/blob/suggest_gitlab_ci_yml/components/popover.vue'; import Popover from '~/blob/suggest_gitlab_ci_yml/components/popover.vue';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import * as utils from '~/lib/utils/common_utils'; import * as utils from '~/lib/utils/common_utils';
jest.mock('~/lib/utils/common_utils', () => ({ jest.mock('~/lib/utils/common_utils', () => ({
...@@ -11,6 +12,8 @@ jest.mock('~/lib/utils/common_utils', () => ({ ...@@ -11,6 +12,8 @@ jest.mock('~/lib/utils/common_utils', () => ({
const target = 'gitlab-ci-yml-selector'; const target = 'gitlab-ci-yml-selector';
const dismissKey = 'suggest_gitlab_ci_yml_99'; const dismissKey = 'suggest_gitlab_ci_yml_99';
const defaultTrackLabel = 'suggest_gitlab_ci_yml'; const defaultTrackLabel = 'suggest_gitlab_ci_yml';
const commitTrackLabel = 'suggest_commit_first_project_gitlab_ci_yml';
const humanAccess = 'owner';
describe('Suggest gitlab-ci.yml Popover', () => { describe('Suggest gitlab-ci.yml Popover', () => {
let wrapper; let wrapper;
...@@ -21,6 +24,7 @@ describe('Suggest gitlab-ci.yml Popover', () => { ...@@ -21,6 +24,7 @@ describe('Suggest gitlab-ci.yml Popover', () => {
target, target,
trackLabel, trackLabel,
dismissKey, dismissKey,
humanAccess,
}, },
}); });
} }
...@@ -50,15 +54,43 @@ describe('Suggest gitlab-ci.yml Popover', () => { ...@@ -50,15 +54,43 @@ describe('Suggest gitlab-ci.yml Popover', () => {
expect(wrapper.vm.popoverDismissed).toEqual(true); expect(wrapper.vm.popoverDismissed).toEqual(true);
}); });
beforeEach(() => { afterEach(() => {
Cookies.remove(dismissKey); Cookies.remove(dismissKey);
}); });
}); });
describe('tracking', () => {
let trackingSpy;
beforeEach(() => {
createWrapper(commitTrackLabel);
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
});
afterEach(() => {
unmockTracking();
});
it('sends a tracking event with the expected properties for the popover being viewed', () => {
const expectedCategory = undefined;
const expectedAction = undefined;
const expectedLabel = 'suggest_commit_first_project_gitlab_ci_yml';
const expectedProperty = 'owner';
document.body.dataset.page = 'projects:blob:new';
wrapper.vm.trackOnShow();
expect(trackingSpy).toHaveBeenCalledWith(expectedCategory, expectedAction, {
label: expectedLabel,
property: expectedProperty,
});
});
});
describe('when the popover is mounted with the trackLabel of the Confirm button popover at the bottom of the page', () => { describe('when the popover is mounted with the trackLabel of the Confirm button popover at the bottom of the page', () => {
it('calls scrollToElement so that the Confirm button and popover will be in sight', () => { it('calls scrollToElement so that the Confirm button and popover will be in sight', () => {
const scrollToElementSpy = jest.spyOn(utils, 'scrollToElement'); const scrollToElementSpy = jest.spyOn(utils, 'scrollToElement');
const commitTrackLabel = 'suggest_commit_first_project_gitlab_ci_yml';
createWrapper(commitTrackLabel); createWrapper(commitTrackLabel);
......
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