Commit 8f063697 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'track-buy-ci-minutes-seen' into 'master'

Track user dropdown click

Closes gitlab-org/growth/product#1493

See merge request gitlab-org/gitlab!28838
parents 73c43e5b 29017076
...@@ -5,6 +5,7 @@ import { highCountTrim } from '~/lib/utils/text_utility'; ...@@ -5,6 +5,7 @@ import { highCountTrim } from '~/lib/utils/text_utility';
import SetStatusModalTrigger from './set_status_modal/set_status_modal_trigger.vue'; import SetStatusModalTrigger from './set_status_modal/set_status_modal_trigger.vue';
import SetStatusModalWrapper from './set_status_modal/set_status_modal_wrapper.vue'; import SetStatusModalWrapper from './set_status_modal/set_status_modal_wrapper.vue';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import Tracking from '~/tracking';
/** /**
* Updates todo counter when todos are toggled. * Updates todo counter when todos are toggled.
...@@ -73,6 +74,24 @@ function initStatusTriggers() { ...@@ -73,6 +74,24 @@ function initStatusTriggers() {
} }
} }
export function initNavUserDropdownTracking() {
const el = document.querySelector('.js-nav-user-dropdown');
const buyEl = document.querySelector('.js-buy-ci-minutes-link');
if (el && buyEl) {
const { trackLabel, trackProperty } = buyEl.dataset;
const trackEvent = 'show_buy_ci_minutes';
$(el).on('shown.bs.dropdown', () => {
Tracking.event(undefined, trackEvent, {
label: trackLabel,
property: trackProperty,
});
});
}
}
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
requestIdleCallback(initStatusTriggers); requestIdleCallback(initStatusTriggers);
initNavUserDropdownTracking();
}); });
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
.dropdown-menu.dropdown-menu-right .dropdown-menu.dropdown-menu-right
= render 'layouts/header/help_dropdown' = render 'layouts/header/help_dropdown'
- if header_link?(:user_dropdown) - if header_link?(:user_dropdown)
%li.nav-item.header-user.dropdown{ data: { track_label: "profile_dropdown", track_event: "click_dropdown", track_value: "", qa_selector: 'user_menu' }, class: ('mr-0' if has_impersonation_link) } %li.nav-item.header-user.js-nav-user-dropdown.dropdown{ data: { track_label: "profile_dropdown", track_event: "click_dropdown", track_value: "", qa_selector: 'user_menu' }, class: ('mr-0' if has_impersonation_link) }
= link_to current_user, class: user_dropdown_class, data: { toggle: "dropdown" } do = link_to current_user, class: user_dropdown_class, data: { toggle: "dropdown" } do
= image_tag avatar_icon_for_user(current_user, 23), width: 23, height: 23, class: "header-user-avatar qa-user-avatar" = image_tag avatar_icon_for_user(current_user, 23), width: 23, height: 23, class: "header-user-avatar qa-user-avatar"
= render_if_exists 'layouts/header/user_notification_dot', project: project, namespace: group = render_if_exists 'layouts/header/user_notification_dot', project: project, namespace: group
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
%li %li
= link_to profile_pipeline_quota_path, = link_to profile_pipeline_quota_path,
class: 'ci-minutes-emoji', class: 'ci-minutes-emoji js-buy-ci-minutes-link',
data: { 'track-event': 'click_buy_ci_minutes', 'track-label': current_user.namespace.actual_plan_name, 'track-property': 'user_dropdown' } do data: { 'track-event': 'click_buy_ci_minutes', 'track-label': current_user.namespace.actual_plan_name, 'track-property': 'user_dropdown' } do
= s_("CurrentUser|Buy CI minutes") = s_("CurrentUser|Buy CI minutes")
= emoji_icon('clock9', 'aria-hidden': true) = emoji_icon('clock9', 'aria-hidden': true)
import $ from 'jquery'; import $ from 'jquery';
import initTodoToggle from '~/header'; import initTodoToggle, { initNavUserDropdownTracking } from '~/header';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
describe('Header', () => { describe('Header', () => {
describe('Todos notification', () => {
const todosPendingCount = '.todos-count'; const todosPendingCount = '.todos-count';
const fixtureTemplate = 'issues/open-issue.html'; const fixtureTemplate = 'issues/open-issue.html';
...@@ -50,4 +52,36 @@ describe('Header', () => { ...@@ -50,4 +52,36 @@ describe('Header', () => {
expect($(todosPendingCount).text()).toEqual('99+'); expect($(todosPendingCount).text()).toEqual('99+');
}); });
}); });
});
describe('Track user dropdown open', () => {
let trackingSpy;
beforeEach(() => {
setFixtures(`
<li class="js-nav-user-dropdown">
<a class="js-buy-ci-minutes-link" data-track-event="click_buy_ci_minutes" data-track-label="free" data-track-property="user_dropdown">Buy CI minutes
</a>
</li>`);
trackingSpy = mockTracking('_category_', $('.js-nav-user-dropdown').element, jest.spyOn);
document.body.dataset.page = 'some:page';
initNavUserDropdownTracking();
});
afterEach(() => {
unmockTracking();
});
it('sends a tracking event when the dropdown is opened and contains Buy CI minutes link', () => {
$('.js-nav-user-dropdown').trigger('shown.bs.dropdown');
expect(trackingSpy).toHaveBeenCalledTimes(1);
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'show_buy_ci_minutes', {
label: 'free',
property: 'user_dropdown',
});
});
});
}); });
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