forked from torch2424/wasmboy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics.js
93 lines (75 loc) · 2.02 KB
/
analytics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import loadScript from 'load-script';
class DebuggerAnalyticsLib {
constructor() {
/*ROLLUP_REPLACE_DEBUGGER_DEV
this.readyPromise = Promise.resolve();
return;
ROLLUP_REPLACE_DEBUGGER_DEV*/
this.readyPromise = new Promise((resolve, reject) => {
if (typeof window !== 'undefined') {
loadScript('https://www.googletagmanager.com/gtag/js?id=UA-125276735-1', (err, script) => {
if (err) {
reject(err);
}
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-125276735-1');
// Attach Analytics to this class
this.gtag = gtag;
resolve();
});
} else {
reject(new Error('Not in a browser Environment'));
}
});
}
_fireAnalyticsEvent(eventAction) {
const fireEventTask = async () => {
await this.readyPromise;
if (this.gtag) {
this.gtag('event', eventAction);
} else {
console.log('Analytics Event Action:', eventAction);
}
};
fireEventTask().catch(() => {
// Do Nothing
});
}
// Define our events
ROMLoadedAndStarted() {
this._fireAnalyticsEvent('rom_loaded_and_started');
}
loadROMSuccess() {
this._fireAnalyticsEvent('load_rom_success');
}
loadROMFail() {
this._fireAnalyticsEvent('load_rom_fail');
}
addBootROMSuccess() {
this._fireAnalyticsEvent('add_boot_rom_success');
}
addBootROMFail() {
this._fireAnalyticsEvent('add_boot_rom_fail');
}
saveState() {
this._fireAnalyticsEvent('save_state');
}
loadState() {
this._fireAnalyticsEvent('load_state');
}
appliedOptions() {
this._fireAnalyticsEvent('applied_options');
}
googleDriveLoad() {
this._fireAnalyticsEvent('google_drive_load');
}
reload() {
this._fireAnalyticsEvent('reload');
}
}
const DebuggerAnalytics = new DebuggerAnalyticsLib();
export default DebuggerAnalytics;