diff options
author | jejacks0n <jjackson@gitlab.com> | 2019-07-30 16:01:33 -0600 |
---|---|---|
committer | jejacks0n <jjackson@gitlab.com> | 2019-07-31 10:32:05 -0600 |
commit | b3ab4f0a4afc218a0e6ee820a490bde697a777af (patch) | |
tree | f8fd59017f042099466eb24528781a8079b62ed6 | |
parent | 68d0132026954d5bc3e1fb2135428ec503b37508 (diff) | |
download | gitlab-ce-snowplow-ee-to-ce.tar.gz |
Adds new tracking interface for snowplowsnowplow-ee-to-ce
This will ultimately replace the stats.js that
exists in EE.
-rw-r--r-- | app/assets/javascripts/tracking.js | 12 | ||||
-rw-r--r-- | spec/frontend/tracking_spec.js | 18 |
2 files changed, 12 insertions, 18 deletions
diff --git a/app/assets/javascripts/tracking.js b/app/assets/javascripts/tracking.js index 76b94137b40..2d0b099cf0b 100644 --- a/app/assets/javascripts/tracking.js +++ b/app/assets/javascripts/tracking.js @@ -1,5 +1,4 @@ import $ from 'jquery'; -import { __ } from '~/locale'; const extractData = (el, opts = {}) => { const { trackEvent, trackLabel = '', trackProperty = '' } = el.dataset; @@ -21,8 +20,9 @@ export default class Tracking { } static event(category = document.body.dataset.page, event = 'generic', data = {}) { - if (!category) throw new Error(__('Tracking: no category provided for tracking.')); if (!this.enabled()) return false; + // eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings + if (!category) throw new Error('Tracking: no category provided for tracking.'); return window.snowplow( 'trackStructEvent', @@ -34,11 +34,11 @@ export default class Tracking { constructor(category = document.body.dataset.page) { this.category = category; - }; + } bind(container = document) { if (!this.constructor.enabled()) return; - container.querySelectorAll(`[data-track-event]`).forEach((el) => { + container.querySelectorAll(`[data-track-event]`).forEach(el => { if (this.customHandlingFor(el)) return; // jquery is required for select2, so we use it always // see: https://github.com/select2/select2/issues/4686 @@ -60,8 +60,8 @@ export default class Tracking { } eventHandler(category = null, opts = {}) { - return (e) => { + return e => { this.constructor.event(category || this.category, ...extractData(e.currentTarget, opts)); }; - }; + } } diff --git a/spec/frontend/tracking_spec.js b/spec/frontend/tracking_spec.js index 1ab96fa9d9b..7e462e9a6ce 100644 --- a/spec/frontend/tracking_spec.js +++ b/spec/frontend/tracking_spec.js @@ -18,16 +18,11 @@ describe('Tracking', () => { it('tracks to snowplow (our current tracking system)', () => { Tracking.event('_category_', '_eventName_', { label: '_label_' }); - expect(snowplowSpy).toHaveBeenCalledWith( - 'trackStructEvent', - '_category_', - '_eventName_', - { - label: '_label_', - property: '', - value: '', - }, - ); + expect(snowplowSpy).toHaveBeenCalledWith('trackStructEvent', '_category_', '_eventName_', { + label: '_label_', + property: '', + value: '', + }); }); it('skips tracking if snowplow is unavailable', () => { @@ -43,10 +38,9 @@ describe('Tracking', () => { expect(snowplowSpy).not.toHaveBeenCalled(); }); - }); - describe("tracking interface events", () => { + describe('tracking interface events', () => { let eventSpy = null; let subject = null; |