mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🐛 fix(analytics): prevent multiple GTM initializations (#4174)
* feat(types): Add global window interface for Google Tag Manager * refactor(Chat/Footer): Move GTM initialization to useEffect for better lifecycle management * fix(hooks): add useEffect to initialize TagManager conditionally
This commit is contained in:
parent
c1c13a69dc
commit
561650d6f9
3 changed files with 24 additions and 14 deletions
|
|
@ -100,10 +100,12 @@ export default function useAppStartup({
|
|||
setAvailableTools({ pluginStore, ...mapPlugins(tools) });
|
||||
}, [allPlugins, user, setAvailableTools]);
|
||||
|
||||
if (startupConfig?.analyticsGtmId) {
|
||||
const tagManagerArgs = {
|
||||
gtmId: startupConfig?.analyticsGtmId,
|
||||
};
|
||||
TagManager.initialize(tagManagerArgs);
|
||||
}
|
||||
useEffect(() => {
|
||||
if (startupConfig?.analyticsGtmId != null && typeof window.google_tag_manager === 'undefined') {
|
||||
const tagManagerArgs = {
|
||||
gtmId: startupConfig.analyticsGtmId,
|
||||
};
|
||||
TagManager.initialize(tagManagerArgs);
|
||||
}
|
||||
}, [startupConfig?.analyticsGtmId]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue