websetup/ts/tools/ganalytics.ts

33 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2019-03-25 14:57:38 +00:00
declare global {
// tslint:disable-next-line: interface-name
interface Window {
analytics: any;
}
}
export const setupGoogleAnalytics = async (gaCode: string) => {
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
(function (i, s, o, g, r, a, m) {
2019-03-25 14:57:38 +00:00
// tslint:disable-next-line: no-string-literal
i['GoogleAnalyticsObject'] = r;
// tslint:disable-next-line: ban-comma-operator
(i[r] =
i[r] ||
// tslint:disable-next-line: only-arrow-functions
2020-06-27 12:50:44 +00:00
function () {
2019-03-25 14:57:38 +00:00
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = new Date().getTime());
// tslint:disable-next-line: ban-comma-operator
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
2019-07-24 09:43:20 +00:00
a.crossorigin = 'anonymous';
2019-03-25 14:57:38 +00:00
m.parentNode.insertBefore(a, m);
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'analytics');
window.analytics('create', gaCode, 'auto');
window.analytics('send', 'pageview');
console.log('Loaded Google Analytics. You may view our privacy policy at https://lossless.gmbh');
};