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';
const TRACKING_CONTEXT_SCHEMA = 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0';
export default class ExperimentTracking {
constructor(experimentName, { label } = {}) {
this.label = label;
constructor(experimentName, trackingArgs = {}) {
this.trackingArgs = trackingArgs;
this.experimentData = get(window, ['gon', 'global', 'experiment', experimentName]);
}
......@@ -15,7 +15,7 @@ export default class ExperimentTracking {
}
return Tracking.event(document.body.dataset.page, action, {
label: this.label,
...this.trackingArgs,
context: {
schema: TRACKING_CONTEXT_SCHEMA,
data: this.experimentData,
......
import ExperimentTracking from '~/experiment_tracking';
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);
}
......
......@@ -329,7 +329,10 @@ class ProjectsController < Projects::ApplicationController
if can?(current_user, :download_code, @project)
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?
record_experiment_user(:invite_members_empty_project_version_a)
......
......@@ -231,7 +231,7 @@ RSpec.describe ProjectsController do
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
......
......@@ -5,13 +5,14 @@ jest.mock('~/tracking');
const oldGon = window.gon;
let newGon = {};
let experimentTracking;
let label;
let newGon = {};
let property;
const setup = () => {
window.gon = newGon;
experimentTracking = new ExperimentTracking('sidebar_experiment', label);
experimentTracking = new ExperimentTracking('sidebar_experiment', { label, property });
};
beforeEach(() => {
......@@ -22,6 +23,7 @@ afterEach(() => {
window.gon = oldGon;
Tracking.mockClear();
label = undefined;
property = undefined;
});
describe('event', () => {
......@@ -32,7 +34,8 @@ describe('event', () => {
});
describe('when providing options', () => {
label = { label: 'sidebar-drawer' };
label = 'sidebar-drawer';
property = 'dark-mode';
it('passes them to the tracking call', () => {
experimentTracking.event('click_sidebar_close');
......@@ -40,6 +43,7 @@ describe('event', () => {
expect(Tracking.event).toHaveBeenCalledTimes(1);
expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_close', {
label: 'sidebar-drawer',
property: 'dark-mode',
context: {
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0',
data: 'experiment-data',
......@@ -53,7 +57,6 @@ describe('event', () => {
expect(Tracking.event).toHaveBeenCalledTimes(1);
expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_trigger', {
label: undefined,
context: {
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0',
data: 'experiment-data',
......
......@@ -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 findTrigger = () => document.querySelector('.js-upload-file-experiment-trigger');
......@@ -29,9 +29,21 @@ describe('trackUploadFileFormSubmitted', () => {
expect(ExperimentTracking).toHaveBeenCalledWith('empty_repo_upload', {
label: 'blob-upload-modal',
property: 'empty',
});
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', () => {
......
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