debian-mirror-gitlab/app/assets/javascripts/vue_shared/directives/track_event.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
581 B
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import Tracking from '~/tracking';
export default {
bind(el, binding) {
el.dataset.trackingOptions = JSON.stringify(binding.value || {});
el.addEventListener('click', () => {
const { category, action, label, property, value } = JSON.parse(el.dataset.trackingOptions);
if (!category || !action) {
return;
}
Tracking.event(category, action, { label, property, value });
});
},
update(el, binding) {
if (binding.value !== binding.oldValue) {
el.dataset.trackingOptions = JSON.stringify(binding.value || {});
}
},
};