Commit faddd7c2 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'jswain_new_repo_tracking' into 'master'

Enhance empty_repo_upload experiment tracking

See merge request gitlab-org/gitlab!55135
parents 9f1e89ae fa598717
...@@ -4,8 +4,8 @@ import Tracking from '~/tracking'; ...@@ -4,8 +4,8 @@ import Tracking from '~/tracking';
const TRACKING_CONTEXT_SCHEMA = 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0'; const TRACKING_CONTEXT_SCHEMA = 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0';
export default class ExperimentTracking { export default class ExperimentTracking {
constructor(experimentName, { label } = {}) { constructor(experimentName, trackingArgs = {}) {
this.label = label; this.trackingArgs = trackingArgs;
this.experimentData = get(window, ['gon', 'global', 'experiment', experimentName]); this.experimentData = get(window, ['gon', 'global', 'experiment', experimentName]);
} }
...@@ -15,7 +15,7 @@ export default class ExperimentTracking { ...@@ -15,7 +15,7 @@ export default class ExperimentTracking {
} }
return Tracking.event(document.body.dataset.page, action, { return Tracking.event(document.body.dataset.page, action, {
label: this.label, ...this.trackingArgs,
context: { context: {
schema: TRACKING_CONTEXT_SCHEMA, schema: TRACKING_CONTEXT_SCHEMA,
data: this.experimentData, data: this.experimentData,
......
import ExperimentTracking from '~/experiment_tracking'; import ExperimentTracking from '~/experiment_tracking';
function trackEvent(eventName) { function trackEvent(eventName) {
const Tracking = new ExperimentTracking('empty_repo_upload', { label: 'blob-upload-modal' }); const isEmpty = Boolean(document.querySelector('.project-home-panel.empty-project'));
const property = isEmpty ? 'empty' : 'nonempty';
const label = 'blob-upload-modal';
const Tracking = new ExperimentTracking('empty_repo_upload', { label, property });
Tracking.event(eventName); Tracking.event(eventName);
} }
......
...@@ -329,7 +329,10 @@ class ProjectsController < Projects::ApplicationController ...@@ -329,7 +329,10 @@ class ProjectsController < Projects::ApplicationController
if can?(current_user, :download_code, @project) if can?(current_user, :download_code, @project)
return render 'projects/no_repo' unless @project.repository_exists? return render 'projects/no_repo' unless @project.repository_exists?
experiment(:empty_repo_upload, project: @project).track(:view_project_show) if @project.can_current_user_push_to_default_branch? if @project.can_current_user_push_to_default_branch?
property = @project.empty_repo? ? 'empty' : 'nonempty'
experiment(:empty_repo_upload, project: @project).track(:view_project_show, property: property)
end
if @project.empty_repo? if @project.empty_repo?
record_experiment_user(:invite_members_empty_project_version_a) record_experiment_user(:invite_members_empty_project_version_a)
......
...@@ -231,7 +231,7 @@ RSpec.describe ProjectsController do ...@@ -231,7 +231,7 @@ RSpec.describe ProjectsController do
get :show, params: { namespace_id: empty_project.namespace, id: empty_project } get :show, params: { namespace_id: empty_project.namespace, id: empty_project }
expect_snowplow_event(category: 'empty_repo_upload', action: 'view_project_show', context: [{ schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0', data: anything }]) expect_snowplow_event(category: 'empty_repo_upload', action: 'view_project_show', context: [{ schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0', data: anything }], property: 'empty')
end end
end end
......
...@@ -5,13 +5,14 @@ jest.mock('~/tracking'); ...@@ -5,13 +5,14 @@ jest.mock('~/tracking');
const oldGon = window.gon; const oldGon = window.gon;
let newGon = {};
let experimentTracking; let experimentTracking;
let label; let label;
let newGon = {}; let property;
const setup = () => { const setup = () => {
window.gon = newGon; window.gon = newGon;
experimentTracking = new ExperimentTracking('sidebar_experiment', label); experimentTracking = new ExperimentTracking('sidebar_experiment', { label, property });
}; };
beforeEach(() => { beforeEach(() => {
...@@ -22,6 +23,7 @@ afterEach(() => { ...@@ -22,6 +23,7 @@ afterEach(() => {
window.gon = oldGon; window.gon = oldGon;
Tracking.mockClear(); Tracking.mockClear();
label = undefined; label = undefined;
property = undefined;
}); });
describe('event', () => { describe('event', () => {
...@@ -32,7 +34,8 @@ describe('event', () => { ...@@ -32,7 +34,8 @@ describe('event', () => {
}); });
describe('when providing options', () => { describe('when providing options', () => {
label = { label: 'sidebar-drawer' }; label = 'sidebar-drawer';
property = 'dark-mode';
it('passes them to the tracking call', () => { it('passes them to the tracking call', () => {
experimentTracking.event('click_sidebar_close'); experimentTracking.event('click_sidebar_close');
...@@ -40,6 +43,7 @@ describe('event', () => { ...@@ -40,6 +43,7 @@ describe('event', () => {
expect(Tracking.event).toHaveBeenCalledTimes(1); expect(Tracking.event).toHaveBeenCalledTimes(1);
expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_close', { expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_close', {
label: 'sidebar-drawer', label: 'sidebar-drawer',
property: 'dark-mode',
context: { context: {
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0', schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0',
data: 'experiment-data', data: 'experiment-data',
...@@ -53,7 +57,6 @@ describe('event', () => { ...@@ -53,7 +57,6 @@ describe('event', () => {
expect(Tracking.event).toHaveBeenCalledTimes(1); expect(Tracking.event).toHaveBeenCalledTimes(1);
expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_trigger', { expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_trigger', {
label: undefined,
context: { context: {
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0', schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0',
data: 'experiment-data', data: 'experiment-data',
......
...@@ -8,7 +8,7 @@ jest.mock('~/experiment_tracking', () => ...@@ -8,7 +8,7 @@ jest.mock('~/experiment_tracking', () =>
})), })),
); );
const fixture = `<a class='js-upload-file-experiment-trigger' data-toggle='modal' data-target='#modal-upload-blob'></a><div id='modal-upload-blob'></div>`; const fixture = `<a class='js-upload-file-experiment-trigger' data-toggle='modal' data-target='#modal-upload-blob'></a><div id='modal-upload-blob'></div><div class='project-home-panel empty-project'></div>`;
const findModal = () => document.querySelector('[aria-modal="true"]'); const findModal = () => document.querySelector('[aria-modal="true"]');
const findTrigger = () => document.querySelector('.js-upload-file-experiment-trigger'); const findTrigger = () => document.querySelector('.js-upload-file-experiment-trigger');
...@@ -29,9 +29,21 @@ describe('trackUploadFileFormSubmitted', () => { ...@@ -29,9 +29,21 @@ describe('trackUploadFileFormSubmitted', () => {
expect(ExperimentTracking).toHaveBeenCalledWith('empty_repo_upload', { expect(ExperimentTracking).toHaveBeenCalledWith('empty_repo_upload', {
label: 'blob-upload-modal', label: 'blob-upload-modal',
property: 'empty',
}); });
expect(mockExperimentTrackingEvent).toHaveBeenCalledWith('click_upload_modal_form_submit'); expect(mockExperimentTrackingEvent).toHaveBeenCalledWith('click_upload_modal_form_submit');
}); });
it('initializes ExperimentTracking with the correct arguments when the project is not empty', () => {
document.querySelector('.empty-project').remove();
UploadFileExperiment.trackUploadFileFormSubmitted();
expect(ExperimentTracking).toHaveBeenCalledWith('empty_repo_upload', {
label: 'blob-upload-modal',
property: 'nonempty',
});
});
}); });
describe('initUploadFileTrigger', () => { describe('initUploadFileTrigger', () => {
......
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