mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-27 16:50:11 +02:00
Firebase is here people!
This commit is contained in:
49
webmaker/src/analytics.js
Normal file
49
webmaker/src/analytics.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
log
|
||||
} from "./utils";
|
||||
|
||||
/* global ga */
|
||||
|
||||
// eslint-disable-next-line max-params
|
||||
export function trackEvent(category, action, label, value) {
|
||||
if (window.DEBUG) {
|
||||
log('trackevent', category, action, label, value);
|
||||
return;
|
||||
}
|
||||
if (window.ga) {
|
||||
ga('send', 'event', category, action, label, value);
|
||||
}
|
||||
};
|
||||
|
||||
// if online, load after sometime
|
||||
if (navigator.onLine && !window.DEBUG) {
|
||||
/* eslint-disable */
|
||||
|
||||
// prettier-ignore
|
||||
setTimeout(function () {
|
||||
(function (i, s, o, g, r, a, m) {
|
||||
i['GoogleAnalyticsObject'] = r;
|
||||
i[r] = i[r] || function () {
|
||||
(i[r].q = i[r].q || []).push(arguments)
|
||||
}, i[r].l = 1 * new Date();
|
||||
a = s.createElement(o),
|
||||
m = s.getElementsByTagName(o)[0];
|
||||
a.async = 1;
|
||||
a.src = g;
|
||||
m.parentNode.insertBefore(a, m)
|
||||
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
|
||||
|
||||
if (location.href.indexOf('chrome-extension://') === -1) {
|
||||
ga('create', 'UA-87786708-1');
|
||||
} else {
|
||||
ga('create', 'UA-87786708-1', {
|
||||
'cookieDomain': 'none'
|
||||
});
|
||||
// required for chrome extension protocol
|
||||
ga('set', 'checkProtocolTask', function () { /* nothing */ });
|
||||
}
|
||||
ga('send', 'pageview');
|
||||
}, 100);
|
||||
|
||||
/* eslint-enable */
|
||||
}
|
Reference in New Issue
Block a user