@mopinion/survey
Version:
Collect customer feedback with the Mopinion survey library
99 lines (98 loc) • 3.67 kB
JavaScript
;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _Track = _interopRequireWildcard(require("./Track"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
describe('it gets the correct analytics ids from page', function () {
afterEach(function () {
window.dataLayer = undefined;
window.ga = undefined;
window.google_tag_manager = undefined;
window.gtag = undefined;
});
test('get UA id legacy', function () {
window.ga = {
getAll: function getAll() {
return [{
get: function get() {
return 'UA-1234';
}
}];
}
};
expect((0, _Track.getAnalyticsIdFromPage)()).toBe('UA-1234');
});
test('get UA id from tagmanager data', function () {
window.google_tag_manager = {
'UA-1234': 'yep'
};
expect((0, _Track.getAnalyticsIdFromPage)()).toBe('UA-1234');
});
test('get GA4 id from datalayer', function () {
window.dataLayer = [];
window.gtag = function () {
window.dataLayer.push(arguments);
};
window.gtag('config', 'G-12345');
expect((0, _Track.getAnalyticsIdFromPage)()).toBe('G-12345');
});
test('get GA4 id from tagmanager data', function () {
window.google_tag_manager = {
'G-12345': 'yep'
};
expect((0, _Track.getAnalyticsIdFromPage)()).toBe('G-12345');
});
test('get GA4 id from datalayer', function () {
window.dataLayer = [];
window.gtag = function () {
window.dataLayer.push(arguments);
};
window.gtag('config', 'G-12345');
expect((0, _Track.getAnalyticsIdFromPage)()).toBe('G-12345');
});
});
describe('track class', function () {
afterEach(function () {
window.dataLayer = undefined;
window.ga = undefined;
window.google_tag_manager = undefined;
window.gtag = undefined;
});
test('it gets the right UA GA tracker name', function () {
window.ga = function () {};
window.ga.getAll = function () {
return [{
get: function get() {
return 'UA-1245';
}
}];
};
var track = new _Track["default"]({
advanced: {
analytics_integration: {
load_analytics: true
}
}
});
expect(track.getGaTracker('send')).toBe('send');
});
test('it gets right right UA GA trackname when using different GA ID', function () {
window.ga = function () {};
window.ga.getAll = function () {
return [{
get: function get() {
return 'UA-1245';
}
}];
};
var track = new _Track["default"]({
advanced: {
analytics_integration: {
load_analytics: true,
GA_TRACKING_ID: 'UA-122'
}
}
});
expect(track.getGaTracker('send')).toBe('mopinion.send');
});
});
//# sourceMappingURL=Track.test.js.map