diff --git a/app/assets/javascripts/pages/shared/wikis/components/wiki_form.vue b/app/assets/javascripts/pages/shared/wikis/components/wiki_form.vue index 2ce1f0366c1012e659339b3796a68601443b219c..6f19a9f43791593c29855c019ee8899968adaff6 100644 --- a/app/assets/javascripts/pages/shared/wikis/components/wiki_form.vue +++ b/app/assets/javascripts/pages/shared/wikis/components/wiki_form.vue @@ -16,9 +16,11 @@ import { __, s__, sprintf } from '~/locale'; import Tracking from '~/tracking'; import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import { - WIKI_CONTENT_EDITOR_TRACKING_LABEL, CONTENT_EDITOR_LOADED_ACTION, SAVED_USING_CONTENT_EDITOR_ACTION, + WIKI_CONTENT_EDITOR_TRACKING_LABEL, + WIKI_FORMAT_LABEL, + WIKI_FORMAT_UPDATED_ACTION, } from '../constants'; const trackingMixin = Tracking.mixin({ @@ -219,6 +221,8 @@ export default { this.trackFormSubmit(); } + this.trackWikiFormat(); + // Wait until form field values are refreshed await this.$nextTick(); @@ -304,6 +308,14 @@ export default { } }, + trackWikiFormat() { + this.track(WIKI_FORMAT_UPDATED_ACTION, { + label: WIKI_FORMAT_LABEL, + value: this.format, + extra: { project_path: this.pageInfo.path, old_format: this.pageInfo.format }, + }); + }, + dismissContentEditorAlert() { this.isContentEditorAlertDismissed = true; }, diff --git a/app/assets/javascripts/pages/shared/wikis/constants.js b/app/assets/javascripts/pages/shared/wikis/constants.js index b358ac9cf5207138209b53fa614f50a2cc5d17d1..94d086158f1a0b378cc33489a78bc23ff31f694d 100644 --- a/app/assets/javascripts/pages/shared/wikis/constants.js +++ b/app/assets/javascripts/pages/shared/wikis/constants.js @@ -1,4 +1,5 @@ -export const WIKI_CONTENT_EDITOR_TRACKING_LABEL = 'wiki_content_editor'; - export const CONTENT_EDITOR_LOADED_ACTION = 'content_editor_loaded'; export const SAVED_USING_CONTENT_EDITOR_ACTION = 'saved_using_content_editor'; +export const WIKI_CONTENT_EDITOR_TRACKING_LABEL = 'wiki_content_editor'; +export const WIKI_FORMAT_LABEL = 'wiki_format'; +export const WIKI_FORMAT_UPDATED_ACTION = 'wiki_format_updated'; diff --git a/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js b/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js index 082a8977710c45003ded0bed5766876519459214..9d510b3d231a59fc66584add3ef589a7ed54d2e1 100644 --- a/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js +++ b/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js @@ -8,9 +8,11 @@ import waitForPromises from 'helpers/wait_for_promises'; import ContentEditor from '~/content_editor/components/content_editor.vue'; import WikiForm from '~/pages/shared/wikis/components/wiki_form.vue'; import { - WIKI_CONTENT_EDITOR_TRACKING_LABEL, CONTENT_EDITOR_LOADED_ACTION, SAVED_USING_CONTENT_EDITOR_ACTION, + WIKI_CONTENT_EDITOR_TRACKING_LABEL, + WIKI_FORMAT_LABEL, + WIKI_FORMAT_UPDATED_ACTION, } from '~/pages/shared/wikis/constants'; import MarkdownField from '~/vue_shared/components/markdown/field.vue'; @@ -65,7 +67,6 @@ describe('WikiForm', () => { const pageInfoPersisted = { ...pageInfoNew, persisted: true, - title: 'My page', content: ' My page content ', format: 'markdown', @@ -177,7 +178,7 @@ describe('WikiForm', () => { await wrapper.vm.$nextTick(); expect(wrapper.text()).toContain(titleHelpText); - expect(findTitleHelpLink().attributes().href).toEqual(titleHelpLink); + expect(findTitleHelpLink().attributes().href).toBe(titleHelpLink); }, ); @@ -186,7 +187,7 @@ describe('WikiForm', () => { await wrapper.vm.$nextTick(); - expect(findMarkdownHelpLink().attributes().href).toEqual( + expect(findMarkdownHelpLink().attributes().href).toBe( '/help/user/markdown#wiki-specific-markdown', ); }); @@ -220,8 +221,8 @@ describe('WikiForm', () => { expect(e.preventDefault).not.toHaveBeenCalled(); }); - it('does not trigger tracking event', async () => { - expect(trackingSpy).not.toHaveBeenCalled(); + it('triggers wiki format tracking event', async () => { + expect(trackingSpy).toHaveBeenCalledTimes(1); }); it('does not trim page content', () => { @@ -273,7 +274,7 @@ describe('WikiForm', () => { ({ persisted, redirectLink }) => { createWrapper(persisted); - expect(findCancelButton().attributes().href).toEqual(redirectLink); + expect(findCancelButton().attributes().href).toBe(redirectLink); }, ); }); @@ -438,7 +439,7 @@ describe('WikiForm', () => { }); }); - it('triggers tracking event on form submit', async () => { + it('triggers tracking events on form submit', async () => { triggerFormSubmit(); await wrapper.vm.$nextTick(); @@ -446,6 +447,15 @@ describe('WikiForm', () => { expect(trackingSpy).toHaveBeenCalledWith(undefined, SAVED_USING_CONTENT_EDITOR_ACTION, { label: WIKI_CONTENT_EDITOR_TRACKING_LABEL, }); + + expect(trackingSpy).toHaveBeenCalledWith(undefined, WIKI_FORMAT_UPDATED_ACTION, { + label: WIKI_FORMAT_LABEL, + value: findFormat().element.value, + extra: { + old_format: pageInfoPersisted.format, + project_path: pageInfoPersisted.path, + }, + }); }); it('updates content from content editor on form submit', async () => {