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 = { const Analytics = {
install(Vue, options) { install(Vue, options) {
const isDoNotTrack = isDoNotTrackEnabled(); 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; delete options.router;
} }
VueSegmentAnalytics.install(Vue, options); VueSegmentAnalytics.install(Vue, options);
/* tslint:disable-next-line */ /* tslint:disable-next-line */
if (isDoNotTrack) { if (isDoNotTrack || !hasSegmentID) {
Vue.$segment.methods.forEach(method => { Vue.$segment.forEach(method => {
Vue.$segment[method] = () => undefined; Vue.$segment[method] = () => undefined;
}); });
} }