2022-05-13 17:08:46 -04:00
|
|
|
import { Tracker } from 'jh_else_ce/tracking/tracker';
|
|
|
|
import { addExperimentContext } from './utils';
|
2021-09-17 14:11:44 -04:00
|
|
|
|
2022-05-13 17:08:46 -04:00
|
|
|
const Tracking = Object.assign(Tracker, {
|
2021-08-10 14:10:13 -04:00
|
|
|
/**
|
|
|
|
* Returns an implementation of this class in the form of
|
|
|
|
* a Vue mixin.
|
|
|
|
*
|
|
|
|
* @param {Object} opts - default options for all events
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-05-13 17:08:46 -04:00
|
|
|
mixin(opts = {}) {
|
2021-08-10 14:10:13 -04:00
|
|
|
return {
|
|
|
|
computed: {
|
|
|
|
trackingCategory() {
|
|
|
|
const localCategory = this.tracking ? this.tracking.category : null;
|
|
|
|
return localCategory || opts.category;
|
|
|
|
},
|
|
|
|
trackingOptions() {
|
|
|
|
const options = addExperimentContext(opts);
|
|
|
|
return { ...options, ...this.tracking };
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
track(action, data = {}) {
|
|
|
|
const category = data.category || this.trackingCategory;
|
|
|
|
const options = {
|
|
|
|
...this.trackingOptions,
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
|
|
|
|
Tracking.event(category, action, options);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-05-13 17:08:46 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Tracking;
|