Commit 6dfb53a8 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'jswain_whats_new_tracking' into 'master'

Add tracking to whats new

See merge request gitlab-org/gitlab!42653
parents b4938556 914a9f38
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { GlDrawer, GlBadge, GlIcon, GlLink } from '@gitlab/ui'; import { GlDrawer, GlBadge, GlIcon, GlLink } from '@gitlab/ui';
import Tracking from '~/tracking';
const trackingMixin = Tracking.mixin();
export default { export default {
components: { components: {
...@@ -9,6 +12,7 @@ export default { ...@@ -9,6 +12,7 @@ export default {
GlIcon, GlIcon,
GlLink, GlLink,
}, },
mixins: [trackingMixin],
props: { props: {
features: { features: {
type: String, type: String,
...@@ -37,6 +41,11 @@ export default { ...@@ -37,6 +41,11 @@ export default {
}, },
mounted() { mounted() {
this.openDrawer(this.storageKey); this.openDrawer(this.storageKey);
const body = document.querySelector('body');
const namespaceId = body.getAttribute('data-namespace-id');
this.track('click_whats_new_drawer', { label: 'namespace_id', value: namespaceId });
}, },
methods: { methods: {
...mapActions(['openDrawer', 'closeDrawer']), ...mapActions(['openDrawer', 'closeDrawer']),
...@@ -52,7 +61,14 @@ export default { ...@@ -52,7 +61,14 @@ export default {
</template> </template>
<div class="pb-6"> <div class="pb-6">
<div v-for="feature in parsedFeatures" :key="feature.title" class="mb-6"> <div v-for="feature in parsedFeatures" :key="feature.title" class="mb-6">
<gl-link :href="feature.url" target="_blank"> <gl-link
:href="feature.url"
target="_blank"
data-testid="whats-new-title-link"
data-track-event="click_whats_new_item"
:data-track-label="feature.title"
:data-track-property="feature.url"
>
<h5 class="gl-font-base">{{ feature.title }}</h5> <h5 class="gl-font-base">{{ feature.title }}</h5>
</gl-link> </gl-link>
<div class="mb-2"> <div class="mb-2">
...@@ -62,7 +78,13 @@ export default { ...@@ -62,7 +78,13 @@ export default {
</gl-badge> </gl-badge>
</template> </template>
</div> </div>
<gl-link :href="feature.url" target="_blank"> <gl-link
:href="feature.url"
target="_blank"
data-track-event="click_whats_new_item"
:data-track-label="feature.title"
:data-track-property="feature.url"
>
<img <img
:alt="feature.title" :alt="feature.title"
:src="feature.image_url" :src="feature.image_url"
...@@ -70,7 +92,14 @@ export default { ...@@ -70,7 +92,14 @@ export default {
/> />
</gl-link> </gl-link>
<p class="pt-2">{{ feature.body }}</p> <p class="pt-2">{{ feature.body }}</p>
<gl-link :href="feature.url" target="_blank">{{ __('Learn more') }}</gl-link> <gl-link
:href="feature.url"
target="_blank"
data-track-event="click_whats_new_item"
:data-track-label="feature.title"
:data-track-property="feature.url"
>{{ __('Learn more') }}</gl-link
>
</div> </div>
</div> </div>
</gl-drawer> </gl-drawer>
......
import { createLocalVue, mount } from '@vue/test-utils'; import { createLocalVue, mount } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { GlDrawer } from '@gitlab/ui'; import { GlDrawer } from '@gitlab/ui';
import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper';
import App from '~/whats_new/components/app.vue'; import App from '~/whats_new/components/app.vue';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -12,6 +13,7 @@ describe('App', () => { ...@@ -12,6 +13,7 @@ describe('App', () => {
let actions; let actions;
let state; let state;
let propsData = { features: '[ {"title":"Whats New Drawer"} ]', storageKey: 'storage-key' }; let propsData = { features: '[ {"title":"Whats New Drawer"} ]', storageKey: 'storage-key' };
let trackingSpy;
const buildWrapper = () => { const buildWrapper = () => {
actions = { actions = {
...@@ -36,11 +38,16 @@ describe('App', () => { ...@@ -36,11 +38,16 @@ describe('App', () => {
}; };
beforeEach(() => { beforeEach(() => {
document.body.dataset.page = 'test-page';
document.body.dataset.namespaceId = 'namespace-840';
trackingSpy = mockTracking('_category_', null, jest.spyOn);
buildWrapper(); buildWrapper();
}); });
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
unmockTracking();
}); });
const getDrawer = () => wrapper.find(GlDrawer); const getDrawer = () => wrapper.find(GlDrawer);
...@@ -50,8 +57,11 @@ describe('App', () => { ...@@ -50,8 +57,11 @@ describe('App', () => {
}); });
it('dispatches openDrawer when mounted', () => { it('dispatches openDrawer when mounted', () => {
expect(actions.openDrawer).toHaveBeenCalled();
expect(actions.openDrawer).toHaveBeenCalledWith(expect.any(Object), 'storage-key'); expect(actions.openDrawer).toHaveBeenCalledWith(expect.any(Object), 'storage-key');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_whats_new_drawer', {
label: 'namespace_id',
value: 'namespace-840',
});
}); });
it('dispatches closeDrawer when clicking close', () => { it('dispatches closeDrawer when clicking close', () => {
...@@ -77,4 +87,25 @@ describe('App', () => { ...@@ -77,4 +87,25 @@ describe('App', () => {
expect(getDrawer().exists()).toBe(true); expect(getDrawer().exists()).toBe(true);
}); });
it('send an event when feature item is clicked', () => {
propsData = {
features: '[ {"title":"Whats New Drawer", "url": "www.url.com"} ]',
storageKey: 'storage-key',
};
buildWrapper();
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
const link = wrapper.find('[data-testid="whats-new-title-link"]');
triggerEvent(link.element);
expect(trackingSpy.mock.calls[2]).toMatchObject([
'_category_',
'click_whats_new_item',
{
label: 'Whats New Drawer',
property: 'www.url.com',
},
]);
});
}); });
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