Commit 85d0e28d authored by Dallas Reedy's avatar Dallas Reedy Committed by Phil Hughes

Add basic click-tracking to widget & buttons

- Make use of the data-track-… attributes
parent 1e7ea614
...@@ -9,6 +9,11 @@ import Tracking from '~/tracking'; ...@@ -9,6 +9,11 @@ import Tracking from '~/tracking';
const RESIZE_EVENT_DEBOUNCE_MS = 150; const RESIZE_EVENT_DEBOUNCE_MS = 150;
export default { export default {
tracking: {
event: 'click_button',
labels: { upgrade: 'upgrade_to_ultimate', compare: 'compare_all_plans' },
property: 'experiment:show_trial_status_in_sidebar',
},
components: { components: {
GlButton, GlButton,
GlPopover, GlPopover,
...@@ -123,6 +128,10 @@ export default { ...@@ -123,6 +128,10 @@ export default {
size="small" size="small"
class="gl-mb-0" class="gl-mb-0"
block block
data-testid="upgradeBtn"
:data-track-event="$options.tracking.event"
:data-track-label="$options.tracking.labels.upgrade"
:data-track-property="$options.tracking.property"
> >
<span class="gl-font-sm"> <span class="gl-font-sm">
<gl-sprintf :message="$options.i18n.upgradeButtonTitle"> <gl-sprintf :message="$options.i18n.upgradeButtonTitle">
...@@ -138,7 +147,11 @@ export default { ...@@ -138,7 +147,11 @@ export default {
size="small" size="small"
class="gl-mb-0" class="gl-mb-0"
block block
data-testid="compareBtn"
:title="$options.i18n.compareAllButtonTitle" :title="$options.i18n.compareAllButtonTitle"
:data-track-event="$options.tracking.event"
:data-track-label="$options.tracking.labels.compare"
:data-track-property="$options.tracking.property"
> >
<span class="gl-font-sm">{{ $options.i18n.compareAllButtonTitle }}</span> <span class="gl-font-sm">{{ $options.i18n.compareAllButtonTitle }}</span>
</gl-button> </gl-button>
......
...@@ -3,6 +3,11 @@ import { GlLink, GlProgressBar } from '@gitlab/ui'; ...@@ -3,6 +3,11 @@ import { GlLink, GlProgressBar } from '@gitlab/ui';
import { n__, sprintf } from '~/locale'; import { n__, sprintf } from '~/locale';
export default { export default {
tracking: {
event: 'click_link',
label: 'trial_status_widget',
property: 'experiment:show_trial_status_in_sidebar',
},
components: { components: {
GlLink, GlLink,
GlProgressBar, GlProgressBar,
...@@ -53,7 +58,14 @@ export default { ...@@ -53,7 +58,14 @@ export default {
</script> </script>
<template> <template>
<gl-link :id="containerId" :title="widgetTitle" :href="plansHref"> <gl-link
:id="containerId"
:title="widgetTitle"
:href="plansHref"
:data-track-event="$options.tracking.event"
:data-track-label="$options.tracking.label"
:data-track-property="$options.tracking.property"
>
<div class="gl-display-flex gl-flex-direction-column gl-align-items-stretch gl-w-full"> <div class="gl-display-flex gl-flex-direction-column gl-align-items-stretch gl-w-full">
<span class="gl-display-flex gl-align-items-center"> <span class="gl-display-flex gl-align-items-center">
<span class="nav-icon-container svg-container"> <span class="nav-icon-container svg-container">
......
...@@ -22,6 +22,10 @@ exports[`TrialStatusPopover component matches the snapshot 1`] = ` ...@@ -22,6 +22,10 @@ exports[`TrialStatusPopover component matches the snapshot 1`] = `
buttontextclasses="" buttontextclasses=""
category="primary" category="primary"
class="gl-mb-0" class="gl-mb-0"
data-testid="upgradeBtn"
data-track-event="click_button"
data-track-label="upgrade_to_ultimate"
data-track-property="experiment:show_trial_status_in_sidebar"
href="transactions/new" href="transactions/new"
icon="" icon=""
size="small" size="small"
...@@ -41,6 +45,10 @@ exports[`TrialStatusPopover component matches the snapshot 1`] = ` ...@@ -41,6 +45,10 @@ exports[`TrialStatusPopover component matches the snapshot 1`] = `
buttontextclasses="" buttontextclasses=""
category="secondary" category="secondary"
class="gl-mb-0" class="gl-mb-0"
data-testid="compareBtn"
data-track-event="click_button"
data-track-label="compare_all_plans"
data-track-property="experiment:show_trial_status_in_sidebar"
href="billing/path-for/group" href="billing/path-for/group"
icon="" icon=""
size="small" size="small"
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
exports[`TrialStatusWidget component without the optional containerId prop matches the snapshot 1`] = ` exports[`TrialStatusWidget component without the optional containerId prop matches the snapshot 1`] = `
<gl-link-stub <gl-link-stub
data-track-event="click_link"
data-track-label="trial_status_widget"
data-track-property="experiment:show_trial_status_in_sidebar"
href="billing/path-for/group" href="billing/path-for/group"
title="Ultimate Trial – 20 days left" title="Ultimate Trial – 20 days left"
> >
......
...@@ -7,6 +7,8 @@ import TrialStatusPopover from 'ee/contextual_sidebar/components/trial_status_po ...@@ -7,6 +7,8 @@ import TrialStatusPopover from 'ee/contextual_sidebar/components/trial_status_po
describe('TrialStatusPopover component', () => { describe('TrialStatusPopover component', () => {
let wrapper; let wrapper;
const getGlButton = (testId) => wrapper.find(`[data-testid="${testId}"]`);
const createComponent = () => { const createComponent = () => {
return shallowMount(TrialStatusPopover, { return shallowMount(TrialStatusPopover, {
propsData: { propsData: {
...@@ -33,6 +35,20 @@ describe('TrialStatusPopover component', () => { ...@@ -33,6 +35,20 @@ describe('TrialStatusPopover component', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
it('renders the upgrade button with correct tracking data attrs', () => {
const attrs = getGlButton('upgradeBtn').attributes();
expect(attrs['data-track-event']).toBe('click_button');
expect(attrs['data-track-label']).toBe('upgrade_to_ultimate');
expect(attrs['data-track-property']).toBe('experiment:show_trial_status_in_sidebar');
});
it('renders the compare plans button with correct tracking data attrs', () => {
const attrs = getGlButton('compareBtn').attributes();
expect(attrs['data-track-event']).toBe('click_button');
expect(attrs['data-track-label']).toBe('compare_all_plans');
expect(attrs['data-track-property']).toBe('experiment:show_trial_status_in_sidebar');
});
describe('methods', () => { describe('methods', () => {
describe('onResize', () => { describe('onResize', () => {
const getGlPopover = () => wrapper.findComponent(GlPopover); const getGlPopover = () => wrapper.findComponent(GlPopover);
......
...@@ -38,6 +38,13 @@ describe('TrialStatusWidget component', () => { ...@@ -38,6 +38,13 @@ describe('TrialStatusWidget component', () => {
it('renders without an id', () => { it('renders without an id', () => {
expect(getGlLink().attributes('id')).toBe(undefined); expect(getGlLink().attributes('id')).toBe(undefined);
}); });
it('renders with the correct tracking data attributes', () => {
const attrs = getGlLink().attributes();
expect(attrs['data-track-event']).toBe('click_link');
expect(attrs['data-track-label']).toBe('trial_status_widget');
expect(attrs['data-track-property']).toBe('experiment:show_trial_status_in_sidebar');
});
}); });
describe('with the optional containerId prop', () => { describe('with the optional containerId prop', () => {
......
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