summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob/blob_links_tracking.js
blob: 713cc3fad05f3eff680b6ae96a3fe726687ef5b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Tracking from '~/tracking';

const eventsToTrack = [
  { selector: '.file-line-blame', property: 'blame' },
  { selector: '.file-line-num', property: 'link' },
];

function addBlobLinksTracking() {
  const containerEl = document.querySelector('.file-holder');

  if (!containerEl) {
    return;
  }

  const eventName = 'click_link';
  const label = 'file_line_action';

  containerEl.addEventListener('click', (e) => {
    eventsToTrack.forEach((event) => {
      if (e.target.matches(event.selector)) {
        Tracking.event(undefined, eventName, {
          label,
          property: event.property,
        });
      }
    });
  });
}

export default addBlobLinksTracking;