Commit eca94c0f authored by Phil Hughes's avatar Phil Hughes

Merge branch '8808-tracking-navbar-links-not-behind-dropdowns-in-snowplow' into 'master'

Resolve "Tracking navbar links not behind dropdowns in Snowplow"

Closes #8808

See merge request gitlab-org/gitlab-ee!9059
parents a8e2ca00 1b885943
import Stats from 'ee/stats'; import Stats from 'ee/stats';
import { mergeUrlParams } from '~/lib/utils/url_utility';
export default function trackNavbarEvents() { export default function trackNavbarEvents() {
const container = '.navbar-gitlab'; const container = '.navbar-gitlab';
const category = 'navbar_top'; const category = 'navbar_top';
const navbar = document.querySelector('.navbar-gitlab');
/**
* intercepts clicks on navbar links
* and adds the 'nav_source=navbar' query parameter
*/
const appendLinkParam = e => {
const NAVSOURCE_KEY = 'nav_source';
const NAVSOURCE_VALUE = 'navbar';
const target = e.target || e.srcElement;
// get closest link in case the target is a wrapping DOM node
const link = target.tagName === 'A' ? target : target.closest('a');
if (link && link.href && link.href.indexOf(`${NAVSOURCE_KEY}=${NAVSOURCE_VALUE}`) === -1) {
const url = mergeUrlParams({ [NAVSOURCE_KEY]: NAVSOURCE_VALUE }, link.href);
link.setAttribute('href', url);
}
};
Stats.bindTrackableContainer(container, category); Stats.bindTrackableContainer(container, category);
if (Stats.snowplowEnabled) {
// track search inputs within frequent-items component // track search inputs within frequent-items component
document document
.querySelectorAll(`${container} .frequent-items-dropdown-container input`) .querySelectorAll(`${container} .frequent-items-dropdown-container input`)
...@@ -18,4 +39,10 @@ export default function trackNavbarEvents() { ...@@ -18,4 +39,10 @@ export default function trackNavbarEvents() {
Stats.trackEvent(category, 'activate_form_input', { label, property: '', value: '' }); Stats.trackEvent(category, 'activate_form_input', { label, property: '', value: '' });
}); });
}); });
if (navbar) {
navbar.addEventListener('click', appendLinkParam);
navbar.addEventListener('contextmenu', appendLinkParam);
}
}
} }
import $ from 'jquery'; import $ from 'jquery';
const snowPlowEnabled = () => typeof window.snowplow === 'function'; const snowplowEnabled = () => typeof window.snowplow === 'function';
const trackEvent = ( const trackEvent = (
category, category,
eventName, eventName,
additionalData = { label: '', property: '', value: '' }, additionalData = { label: '', property: '', value: '' },
) => { ) => {
if (!snowPlowEnabled()) { if (!snowplowEnabled()) {
return; return;
} }
...@@ -33,7 +33,7 @@ const isBsDropdown = element => { ...@@ -33,7 +33,7 @@ const isBsDropdown = element => {
}; };
const bindTrackableContainer = (container = '', category = document.body.dataset.page) => { const bindTrackableContainer = (container = '', category = document.body.dataset.page) => {
if (!snowPlowEnabled()) { if (!snowplowEnabled()) {
return; return;
} }
...@@ -92,6 +92,7 @@ const bindTrackableContainer = (container = '', category = document.body.dataset ...@@ -92,6 +92,7 @@ const bindTrackableContainer = (container = '', category = document.body.dataset
}; };
export default { export default {
snowplowEnabled,
trackEvent, trackEvent,
bindTrackableContainer, bindTrackableContainer,
}; };
---
title: Track navbar links in Snowplow
merge_request: 9059
author:
type: other
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