improve analytics api
This commit is contained in:
@@ -1,33 +1,33 @@
|
||||
import { storage } from './utils.js';
|
||||
|
||||
const analyticsPreferences = storage('analytics');
|
||||
export default () => new Promise(async (resolve, reject) => {
|
||||
const analyticsPreferences = storage('analytics');
|
||||
|
||||
if (analyticsPreferences.get('enabled') !== false) {
|
||||
var analyticsData;
|
||||
if (analyticsPreferences.get('enabled') !== false) {
|
||||
var analyticsData;
|
||||
|
||||
if (!analyticsPreferences.get('savedResponse')) {
|
||||
try {
|
||||
analyticsData = await (await fetch('/api/analytics/site/' + location.hostname)).json();
|
||||
analyticsPreferences.set('savedResponse', analyticsData);
|
||||
} catch (e) { analyticsPreferences.set('enabled', false);location.reload(); }
|
||||
} else analyticsData = analyticsPreferences.get('savedResponse');
|
||||
if (!analyticsPreferences.get('savedResponse')) {
|
||||
try {
|
||||
analyticsData = await (await fetch('/api/analytics/site/' + location.hostname)).json();
|
||||
analyticsPreferences.set('savedResponse', analyticsData);
|
||||
} catch (e) { analyticsPreferences.set('enabled', false); resolve({}); }
|
||||
} else analyticsData = analyticsPreferences.get('savedResponse');
|
||||
|
||||
if (analyticsData.success && analyticsData.data.domain === location.hostname) {
|
||||
analyticsPreferences.set('enabled', true);
|
||||
if (analyticsData.success && analyticsData.data.domain === location.hostname) {
|
||||
analyticsPreferences.set('enabled', true);
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.src = '/api/analytics/script.js';
|
||||
script.setAttribute('data-website-id', analyticsData.data.id);
|
||||
script.setAttribute('data-auto-track', 'false');
|
||||
script.setAttribute('data-host-url', location.origin + '/api/analytics');
|
||||
script.setAttribute('data-cache', 'true');
|
||||
document.head.appendChild(script);
|
||||
} else analyticsPreferences.set('enabled', false);
|
||||
}
|
||||
const script = document.createElement('script');
|
||||
script.src = '/api/analytics/script.js';
|
||||
script.setAttribute('data-website-id', analyticsData.data.id);
|
||||
script.setAttribute('data-auto-track', 'false');
|
||||
script.setAttribute('data-host-url', location.origin + '/api/analytics');
|
||||
script.setAttribute('data-cache', 'true');
|
||||
document.head.appendChild(script);
|
||||
|
||||
/**
|
||||
* @property {{ track: (event: string, props: {}) => {}}} umami
|
||||
*/
|
||||
var { umami } = window;
|
||||
|
||||
export { umami };
|
||||
script.onload = () => resolve(window.umami);
|
||||
} else {
|
||||
analyticsPreferences.set('enabled', false);
|
||||
resolve({});
|
||||
}
|
||||
} else resolve({});
|
||||
});
|
||||
@@ -1,12 +1,14 @@
|
||||
import { createViewPage, isValidURL, getVH, CrossTabCommunication, PolarisError, storage } from './utils.js';
|
||||
import { loadSettings, loadSidebarInterface } from './settings.js';
|
||||
import loadEasterEggs from './eastereggs.js';
|
||||
import { umami } from './analytics.js';
|
||||
import loadAnalytics from './analytics.js';
|
||||
import Search from './search.js';
|
||||
import Cheats from './cheats.js';
|
||||
import Games from './games.js';
|
||||
import Apps from './apps.js';
|
||||
|
||||
const umami = loadAnalytics();
|
||||
|
||||
if (location.pathname !== '/view') loadSidebarInterface();
|
||||
loadEasterEggs();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user