All files / app/assets/javascripts/vue_shared/directives track_event.js

100% Statements 8/8
80% Branches 8/10
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21        160x   160x 6x 6x 1x   5x       87x 87x        
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) {
    Eif (binding.value !== binding.oldValue) {
      el.dataset.trackingOptions = JSON.stringify(binding.value || {});
    }
  },
};