mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Analytics: track generic events through the server (#12735)
* Loggly-only user support events (#12676) * feat(analytics): Loggly-only user support events * fix(analytics): clean up more Unknowns * wip: allow tracking events from the server * analytics: allow tracking generic events on the server * remove console.logs * remove console.log (client) * add integration test Co-authored-by: Sabe Jones <sabrecat@gmail.com>
This commit is contained in:
@@ -82,14 +82,21 @@ export function setUser () {
|
||||
window.ga('set', { userId: user._id });
|
||||
}
|
||||
|
||||
export function track (properties) {
|
||||
export function track (properties, options = {}) {
|
||||
// Use nextTick to avoid blocking the UI
|
||||
Vue.nextTick(() => {
|
||||
if (_doesNotHaveRequiredFields(properties)) return;
|
||||
if (_doesNotHaveAllowedHitType(properties)) return;
|
||||
|
||||
amplitude.getInstance().logEvent(properties.eventAction, properties);
|
||||
window.ga('send', properties);
|
||||
const trackOnServer = options && options.trackOnServer === true;
|
||||
if (trackOnServer === true) {
|
||||
// Track an event on the server
|
||||
const store = getStore();
|
||||
store.dispatch('analytics:trackEvent', properties);
|
||||
} else {
|
||||
amplitude.getInstance().logEvent(properties.eventAction, properties);
|
||||
window.ga('send', properties);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user