Fix analytics service and audio recorder
This commit is contained in:
parent
2e46a0b663
commit
d4041ab9ab
6 changed files with 90 additions and 1356 deletions
|
|
@ -1,67 +1,64 @@
|
|||
import cleaninsights from './cleaninsights.service'
|
||||
import matomo from './matomo.service'
|
||||
import cleaninsights from "./cleaninsights.service";
|
||||
import matomo from "./matomo.service";
|
||||
|
||||
export default {
|
||||
install(app) {
|
||||
const analyticsService = ({
|
||||
data() {
|
||||
return {
|
||||
engines: [],
|
||||
cachedEvents: [],
|
||||
initialized: false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.$config.promise.then((config) => {
|
||||
var analytics = config.analytics || {};
|
||||
if (!Array.isArray(analytics)) {
|
||||
analytics = [analytics];
|
||||
}
|
||||
for (const engineConfig of analytics) {
|
||||
if (engineConfig.enabled) {
|
||||
let type = engineConfig.type || "ci";
|
||||
switch (type) {
|
||||
case "ci":
|
||||
{
|
||||
let engine = cleaninsights.install(Vue, engineConfig.config);
|
||||
this.engines.push(engine);
|
||||
}
|
||||
break;
|
||||
case "matomo":
|
||||
{
|
||||
let engine = matomo.install(Vue, engineConfig.config);
|
||||
this.engines.push(engine);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
install(app) {
|
||||
class AnalyticsServiceClass {
|
||||
constructor() {
|
||||
this.engines = [];
|
||||
this.cachedEvents = [];
|
||||
this.initialized = false;
|
||||
|
||||
this.initialized = true;
|
||||
|
||||
// Handle cached events
|
||||
this.cachedEvents.forEach(([category, action]) => {
|
||||
this.event(category, action);
|
||||
})
|
||||
this.cachedEvents = [];
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
event(category, action) {
|
||||
if (!this.initialized) {
|
||||
this.cachedEvents.push([category, action]);
|
||||
return
|
||||
}
|
||||
|
||||
// Send the event to each configured analytics engine.
|
||||
this.engines.forEach((engine) => {
|
||||
engine.event(category, action);
|
||||
});
|
||||
}
|
||||
app.$config.promise.then((config) => {
|
||||
var analytics = config.analytics || {};
|
||||
if (!Array.isArray(analytics)) {
|
||||
analytics = [analytics];
|
||||
}
|
||||
for (const engineConfig of analytics) {
|
||||
if (engineConfig.enabled) {
|
||||
let type = engineConfig.type || "ci";
|
||||
switch (type) {
|
||||
case "ci":
|
||||
{
|
||||
let engine = cleaninsights.install(Vue, engineConfig.config);
|
||||
this.engines.push(engine);
|
||||
}
|
||||
break;
|
||||
case "matomo":
|
||||
{
|
||||
let engine = matomo.install(Vue, engineConfig.config);
|
||||
this.engines.push(engine);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.$analytics = analyticsService;
|
||||
app.config.globalProperties.$analytics = analyticsService;
|
||||
this.initialized = true;
|
||||
|
||||
// Handle cached events
|
||||
this.cachedEvents.forEach(([category, action]) => {
|
||||
this.event(category, action);
|
||||
});
|
||||
this.cachedEvents = [];
|
||||
});
|
||||
}
|
||||
|
||||
event(category, action) {
|
||||
if (!this.initialized) {
|
||||
this.cachedEvents.push([category, action]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Send the event to each configured analytics engine.
|
||||
this.engines.forEach((engine) => {
|
||||
engine.event(category, action);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const analyticsService = new AnalyticsServiceClass();
|
||||
app.$analytics = analyticsService;
|
||||
app.config.globalProperties.$analytics = analyticsService;
|
||||
},
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue