Commit 051c4e11 authored by Dallas Reedy's avatar Dallas Reedy Committed by Jose Ivan Vargas

Add CTA tracking options hand_raise_lead_button.vue component

Also adds the ability to pass those options into the hand_raise_props
helper method.
parent 7469f448
...@@ -56,7 +56,7 @@ export default { ...@@ -56,7 +56,7 @@ export default {
GlModal: GlModalDirective, GlModal: GlModalDirective,
}, },
mixins: [Tracking.mixin()], mixins: [Tracking.mixin()],
inject: ['user', 'small'], inject: ['user', 'small', 'ctaTracking'],
data() { data() {
return { return {
isLoading: false, isLoading: false,
...@@ -222,6 +222,11 @@ export default { ...@@ -222,6 +222,11 @@ export default {
:variant="small ? 'confirm' : 'default'" :variant="small ? 'confirm' : 'default'"
:size="small ? 'small' : 'medium'" :size="small ? 'small' : 'medium'"
:class="{ 'gl-mb-3 gl-w-full': small }" :class="{ 'gl-mb-3 gl-w-full': small }"
:data-track-action="ctaTracking.action"
:data-track-label="ctaTracking.label"
:data-track-property="ctaTracking.property"
:data-track-value="ctaTracking.value"
:data-track-experiment="ctaTracking.experiment"
> >
<span :class="{ 'gl-font-sm': small }">{{ $options.i18n.buttonText }}</span> <span :class="{ 'gl-font-sm': small }">{{ $options.i18n.buttonText }}</span>
</gl-button> </gl-button>
......
...@@ -3,7 +3,19 @@ import HandRaiseLeadButton from 'ee/hand_raise_leads/hand_raise_lead/components/ ...@@ -3,7 +3,19 @@ import HandRaiseLeadButton from 'ee/hand_raise_leads/hand_raise_lead/components/
import apolloProvider from 'ee/subscriptions/buy_addons_shared/graphql'; import apolloProvider from 'ee/subscriptions/buy_addons_shared/graphql';
export const initHandRaiseLeadButton = (el) => { export const initHandRaiseLeadButton = (el) => {
const { namespaceId, userName, firstName, lastName, companyName, glmContent } = el.dataset; const {
namespaceId,
userName,
firstName,
lastName,
companyName,
glmContent,
trackAction,
trackLabel,
trackProperty,
trackValue,
trackExperiment,
} = el.dataset;
return new Vue({ return new Vue({
el, el,
...@@ -18,6 +30,13 @@ export const initHandRaiseLeadButton = (el) => { ...@@ -18,6 +30,13 @@ export const initHandRaiseLeadButton = (el) => {
companyName, companyName,
glmContent, glmContent,
}, },
ctaTracking: {
action: trackAction,
label: trackLabel,
property: trackProperty,
value: trackValue,
experiment: trackExperiment,
},
}, },
render(createElement) { render(createElement) {
return createElement(HandRaiseLeadButton); return createElement(HandRaiseLeadButton);
......
...@@ -21,10 +21,10 @@ describe('HandRaiseLeadButton', () => { ...@@ -21,10 +21,10 @@ describe('HandRaiseLeadButton', () => {
let wrapper; let wrapper;
let trackingSpy; let trackingSpy;
const createComponent = (small = false) => { const createComponent = (providers = {}) => {
return shallowMountExtended(HandRaiseLeadButton, { return shallowMountExtended(HandRaiseLeadButton, {
provide: { provide: {
small, small: false,
user: { user: {
namespaceId: '1', namespaceId: '1',
userName: 'joe', userName: 'joe',
...@@ -33,6 +33,8 @@ describe('HandRaiseLeadButton', () => { ...@@ -33,6 +33,8 @@ describe('HandRaiseLeadButton', () => {
companyName: 'ACME', companyName: 'ACME',
glmContent: 'some-content', glmContent: 'some-content',
}, },
ctaTracking: {},
...providers,
}, },
}); });
}; };
...@@ -119,7 +121,7 @@ describe('HandRaiseLeadButton', () => { ...@@ -119,7 +121,7 @@ describe('HandRaiseLeadButton', () => {
describe('small button', () => { describe('small button', () => {
it('has small confirm button and the "Contact sales" text on the button', () => { it('has small confirm button and the "Contact sales" text on the button', () => {
wrapper = createComponent(true); wrapper = createComponent({ small: true });
const button = findButton(); const button = findButton();
expect(button.props('variant')).toBe('confirm'); expect(button.props('variant')).toBe('confirm');
...@@ -129,6 +131,80 @@ describe('HandRaiseLeadButton', () => { ...@@ -129,6 +131,80 @@ describe('HandRaiseLeadButton', () => {
}); });
}); });
describe('when provided with CTA tracking options', () => {
const action = 'click_button';
const label = 'contact sales';
const experiment = 'some_experiment';
describe('when provided with all of the CTA tracking options', () => {
const property = 'a thing';
const value = '123';
beforeEach(() => {
wrapper = createComponent({
ctaTracking: { action, label, property, value, experiment },
});
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
it('sets up tracking on the CTA button', () => {
const button = findButton();
expect(button.attributes()).toMatchObject({
'data-track-action': action,
'data-track-label': label,
'data-track-property': property,
'data-track-value': value,
'data-track-experiment': experiment,
});
button.trigger('click');
expect(trackingSpy).toHaveBeenCalledWith('_category_', action, { label, property, value });
});
});
describe('when provided with some of the CTA tracking options', () => {
beforeEach(() => {
wrapper = createComponent({
ctaTracking: { action, label, experiment },
});
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
it('sets up tracking on the CTA button', () => {
const button = findButton();
expect(button.attributes()).toMatchObject({
'data-track-action': action,
'data-track-label': label,
'data-track-experiment': experiment,
});
button.trigger('click');
expect(trackingSpy).toHaveBeenCalledWith('_category_', action, { label });
});
});
describe('when provided with none of the CTA tracking options', () => {
beforeEach(() => {
wrapper = createComponent();
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
it('does not set up tracking on the CTA button', () => {
const button = findButton();
expect(button.attributes()).not.toMatchObject({ 'data-track-action': action });
button.trigger('click');
expect(trackingSpy).not.toHaveBeenCalled();
});
});
});
describe('submit button', () => { describe('submit button', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent();
......
...@@ -35,6 +35,7 @@ describe('Card security discover app', () => { ...@@ -35,6 +35,7 @@ describe('Card security discover app', () => {
lastName: 'Doe', lastName: 'Doe',
companyName: 'ACME', companyName: 'ACME',
}, },
ctaTracking: {},
}, },
}); });
}; };
......
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