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();
|
const user = _getConsentedUser();
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
await Vue.loadScript(`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`);
|
await Vue.loadScript(`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`);
|
||||||
if (DEBUG_ENABLED || !IS_PRODUCTION) {
|
window.gtag('config', GA_ID, {
|
||||||
window.gtag('config', GA_ID, { debug_mode: true });
|
debug_mode: DEBUG_ENABLED || !IS_PRODUCTION,
|
||||||
}
|
user_id: user._id,
|
||||||
|
});
|
||||||
amplitude.getInstance().init(AMPLITUDE_KEY);
|
amplitude.getInstance().init(AMPLITUDE_KEY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,6 +121,9 @@ export async function appleAuth (store, params) {
|
|||||||
export function logout (store, options = {}) {
|
export function logout (store, options = {}) {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
if (window.gtag) {
|
||||||
|
window.gtag('config', GA_ID, { user_id: null });
|
||||||
|
}
|
||||||
const query = options.redirectToLogin === true ? '?redirectToLogin=true' : '';
|
const query = options.redirectToLogin === true ? '?redirectToLogin=true' : '';
|
||||||
window.location.href = `/logout-server${query}`;
|
window.location.href = `/logout-server${query}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user