mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
fix(analytics): record user ID in GA if consented
This commit is contained in:
@@ -106,8 +106,9 @@ export async function setup () {
|
||||
const user = _getConsentedUser();
|
||||
if (!user) return;
|
||||
await Vue.loadScript(`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`);
|
||||
if (DEBUG_ENABLED || !IS_PRODUCTION) {
|
||||
window.gtag('config', GA_ID, { debug_mode: true });
|
||||
}
|
||||
window.gtag('config', GA_ID, {
|
||||
debug_mode: DEBUG_ENABLED || !IS_PRODUCTION,
|
||||
user_id: user._id,
|
||||
});
|
||||
amplitude.getInstance().init(AMPLITUDE_KEY);
|
||||
}
|
||||
|
||||
@@ -121,6 +121,9 @@ export async function appleAuth (store, params) {
|
||||
export function logout (store, options = {}) {
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
if (window.gtag) {
|
||||
window.gtag('config', GA_ID, { user_id: null });
|
||||
}
|
||||
const query = options.redirectToLogin === true ? '?redirectToLogin=true' : '';
|
||||
window.location.href = `/logout-server${query}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user