add fake id so there's always a segment instance created on Vue (#2214)

This commit is contained in:
Yingrong Zhao 2019-06-14 11:33:44 -04:00 committed by Yaroslav Vorobiov
parent 7d5e425d89
commit 1a5483221a

View File

@ -7,16 +7,21 @@ import { isDoNotTrackEnabled } from '@/utils/doNotTrack';
const Analytics = {
install(Vue, options) {
const isDoNotTrack = isDoNotTrackEnabled();
const hasSegmentID = options.id && options.id.length > 0;
if (isDoNotTrack && options.router != undefined) {
if (!hasSegmentID) {
options.id = "fake id";
}
if ((isDoNotTrack || !hasSegmentID) && options.router != undefined) {
delete options.router;
}
VueSegmentAnalytics.install(Vue, options);
/* tslint:disable-next-line */
if (isDoNotTrack) {
Vue.$segment.methods.forEach(method => {
if (isDoNotTrack || !hasSegmentID) {
Vue.$segment.forEach(method => {
Vue.$segment[method] = () => undefined;
});
}