Commit d907b3d5 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'vs/track-zuora-cc-events' into 'master'

Track Zuora CC validation events

See merge request gitlab-org/gitlab!83929
parents 1624438f b05171a5
<script> <script>
import { GlLoadingIcon, GlAlert } from '@gitlab/ui'; import { GlLoadingIcon, GlAlert } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import Tracking from '~/tracking';
import { objectToQuery } from '~/lib/utils/url_utility'; import { objectToQuery } from '~/lib/utils/url_utility';
const ZUORA_CLIENT_ERROR_HEIGHT = 15; const ZUORA_CLIENT_ERROR_HEIGHT = 15;
const IFRAME_QUERY = Object.freeze({ const IFRAME_QUERY = Object.freeze({
enable_submit: false, enable_submit: false,
user_id: null, user_id: null,
location: null,
}); });
const I18N = { const I18N = {
iframeNotSupported: __('Your browser does not support iFrames'), iframeNotSupported: __('Your browser does not support iFrames'),
}; };
...@@ -17,6 +20,7 @@ export default { ...@@ -17,6 +20,7 @@ export default {
GlLoadingIcon, GlLoadingIcon,
GlAlert, GlAlert,
}, },
mixins: [Tracking.mixin({ category: 'Zuora_cc' })],
props: { props: {
iframeUrl: { iframeUrl: {
type: String, type: String,
...@@ -40,7 +44,11 @@ export default { ...@@ -40,7 +44,11 @@ export default {
}, },
computed: { computed: {
iframeSrc() { iframeSrc() {
const query = { ...IFRAME_QUERY, user_id: gon.current_user_id }; const query = {
...IFRAME_QUERY,
user_id: gon.current_user_id,
location: btoa(window.location.href),
};
return `${this.iframeUrl}?${objectToQuery(query)}`; return `${this.iframeUrl}?${objectToQuery(query)}`;
}, },
...@@ -55,6 +63,7 @@ export default { ...@@ -55,6 +63,7 @@ export default {
}, },
methods: { methods: {
handleFrameLoaded() { handleFrameLoaded() {
this.track('iframe_loaded');
this.isLoading = false; this.isLoading = false;
window.addEventListener('message', this.handleFrameMessages, true); window.addEventListener('message', this.handleFrameMessages, true);
}, },
...@@ -71,13 +80,16 @@ export default { ...@@ -71,13 +80,16 @@ export default {
} }
if (event.data.success) { if (event.data.success) {
this.track('success');
this.$emit('success'); this.$emit('success');
} else if (parseInt(event.data.code, 10) < 7) { } else if (parseInt(event.data.code, 10) < 7) {
// 0-6 error codes mean client-side validation error after submit, // 0-6 error codes mean client-side validation error after submit,
// no need to reload the iframe and emit the failure event // no need to reload the iframe and emit the failure event
// Add a 15px height to the iframe to accomodate the error message // Add a 15px height to the iframe to accomodate the error message
this.iframeHeight += ZUORA_CLIENT_ERROR_HEIGHT; this.iframeHeight += ZUORA_CLIENT_ERROR_HEIGHT;
this.track('client_error');
} else if (parseInt(event.data.code, 10) > 6) { } else if (parseInt(event.data.code, 10) > 6) {
this.track('error');
this.error = event.data.msg; this.error = event.data.msg;
window.removeEventListener('message', this.handleFrameMessages, true); window.removeEventListener('message', this.handleFrameMessages, true);
this.$refs.zuora.src = this.iframeSrc; this.$refs.zuora.src = this.iframeSrc;
......
import { GlLoadingIcon, GlAlert } from '@gitlab/ui'; import { GlLoadingIcon, GlAlert } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Zuora from 'ee/billings/components/zuora.vue'; import Zuora from 'ee/billings/components/zuora.vue';
import { mockTracking } from 'helpers/tracking_helper';
describe('Zuora', () => { describe('Zuora', () => {
let wrapper; let wrapper;
let addEventListenerSpy;
let postMessageSpy;
let removeEventListenerSpy;
let trackingSpy;
const createComponent = (data = {}) => { const createComponent = (data = {}) => {
wrapper = shallowMount(Zuora, { wrapper = shallowMount(Zuora, {
...@@ -16,15 +21,12 @@ describe('Zuora', () => { ...@@ -16,15 +21,12 @@ describe('Zuora', () => {
return data; return data;
}, },
}); });
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
}; };
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const findAlert = () => wrapper.findComponent(GlAlert); const findAlert = () => wrapper.findComponent(GlAlert);
let addEventListenerSpy;
let postMessageSpy;
let removeEventListenerSpy;
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -57,6 +59,12 @@ describe('Zuora', () => { ...@@ -57,6 +59,12 @@ describe('Zuora', () => {
true, true,
); );
}); });
it('tracks frame_loaded event', () => {
expect(trackingSpy).toHaveBeenCalledWith('Zuora_cc', 'iframe_loaded', {
category: 'Zuora_cc',
});
});
}); });
describe('on submit', () => { describe('on submit', () => {
...@@ -122,6 +130,10 @@ describe('Zuora', () => { ...@@ -122,6 +130,10 @@ describe('Zuora', () => {
it('emits the success event', () => { it('emits the success event', () => {
expect(wrapper.emitted('success')).toBeDefined(); expect(wrapper.emitted('success')).toBeDefined();
}); });
it('tracks success event', () => {
expect(trackingSpy).toHaveBeenCalledWith('Zuora_cc', 'success', { category: 'Zuora_cc' });
});
}); });
describe('when not from an allowed origin', () => { describe('when not from an allowed origin', () => {
...@@ -151,6 +163,12 @@ describe('Zuora', () => { ...@@ -151,6 +163,12 @@ describe('Zuora', () => {
it('increases the iframe height', () => { it('increases the iframe height', () => {
expect(wrapper.vm.iframeHeight).toBe(315); expect(wrapper.vm.iframeHeight).toBe(315);
}); });
it('tracks client side Zuora error', () => {
expect(trackingSpy).toHaveBeenCalledWith('Zuora_cc', 'client_error', {
category: 'Zuora_cc',
});
});
}); });
describe('when failure and code greater than 6', () => { describe('when failure and code greater than 6', () => {
...@@ -178,6 +196,10 @@ describe('Zuora', () => { ...@@ -178,6 +196,10 @@ describe('Zuora', () => {
true, true,
); );
}); });
it('tracks Zuora error', () => {
expect(trackingSpy).toHaveBeenCalledWith('Zuora_cc', 'error', { category: 'Zuora_cc' });
});
}); });
}); });
......
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