websetup/ts/tools/fullstory.ts

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-03-25 14:57:38 +00:00
declare global {
// tslint:disable-next-line: interface-name
interface Window {
2020-03-06 15:26:26 +00:00
_fs_debug: boolean;
2019-03-25 14:57:38 +00:00
_fs_host: any;
2020-03-06 15:26:26 +00:00
_fs_org: string;
_fs_namespace: string;
2019-03-25 14:57:38 +00:00
}
}
2019-03-25 15:07:04 +00:00
export const setupFullStory = async (fsCodeArg: string) => {
2019-03-25 14:57:38 +00:00
// tslint:disable-next-line: no-string-literal
window['_fs_debug'] = false;
// tslint:disable-next-line: no-string-literal
window['_fs_host'] = 'fullstory.com';
// tslint:disable-next-line: no-string-literal
2019-03-25 15:07:04 +00:00
window['_fs_org'] = fsCodeArg;
2019-03-25 14:57:38 +00:00
// tslint:disable-next-line: no-string-literal
window['_fs_namespace'] = 'FS';
2020-03-06 15:26:26 +00:00
((m, n, e, t, l, o, g, y) => {
2019-03-25 14:57:38 +00:00
if (e in m) {
if (m.console && m.console.log) {
m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');
}
return;
}
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
g = m[e] = function (a, b, s) {
2019-03-25 14:57:38 +00:00
g.q ? g.q.push([a, b, s]) : g._api(a, b, s);
};
g.q = [];
o = n.createElement(t);
o.async = 1;
o.src = 'https://' + window._fs_host + '/s/fs.js';
2019-07-24 09:43:20 +00:00
o.crossorigin = 'anonymous';
2019-03-25 14:57:38 +00:00
y = n.getElementsByTagName(t)[0];
y.parentNode.insertBefore(o, y);
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
g.identify = function (i, v, s) {
2019-03-25 14:57:38 +00:00
g(l, { uid: i }, s);
if (v) g(l, v, s);
};
2020-06-27 12:50:44 +00:00
g.setUserVars = function (v, s) {
2019-03-25 14:57:38 +00:00
g(l, v, s);
};
2020-06-27 12:50:44 +00:00
g.event = function (i, v, s) {
2019-03-25 14:57:38 +00:00
g('event', { n: i, p: v }, s);
};
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
g.shutdown = function () {
2019-03-25 14:57:38 +00:00
g('rec', !1);
};
2020-06-27 12:50:44 +00:00
g.restart = function () {
2019-03-25 14:57:38 +00:00
g('rec', !0);
};
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
g.consent = function (a) {
2019-03-25 14:57:38 +00:00
g('consent', !arguments.length || a);
};
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
g.identifyAccount = function (i, v) {
2019-03-25 14:57:38 +00:00
o = 'account';
v = v || {};
v.acctId = i;
g(o, v);
};
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
g.clearUserCookie = function () {};
2019-03-25 14:57:38 +00:00
// tslint:disable-next-line: no-string-literal
})(window, document, window['_fs_namespace'], 'script', 'user');
};