📊 feat: Google tag manager integration (#2469)

* Google tag manager integration

* change location of react-gtm-module package

* refactor: move react-gtm-module usage from Chat/Footer to useAppStartup hook

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Denis Palnitsky 2024-06-15 14:09:18 +02:00 committed by GitHub
parent 4416f69a9b
commit 97d12d03d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 29 additions and 0 deletions

View file

@ -74,6 +74,7 @@
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.2.0",
"react-flip-toolkit": "^7.1.0",
"react-gtm-module": "^2.0.11",
"react-hook-form": "^7.43.9",
"react-lazy-load-image-component": "^1.6.0",
"react-markdown": "^8.0.6",

View file

@ -1,9 +1,11 @@
import React from 'react';
import ReactMarkdown from 'react-markdown';
import TagManager from 'react-gtm-module';
import { Constants } from 'librechat-data-provider';
import { useGetStartupConfig } from 'librechat-data-provider/react-query';
import { useLocalize } from '~/hooks';
export default function Footer({ className }: { className?: string }) {
const { data: config } = useGetStartupConfig();
const localize = useLocalize();
@ -33,6 +35,13 @@ export default function Footer({ className }: { className?: string }) {
</a>
);
if (config?.analyticsGtmId) {
const tagManagerArgs = {
gtmId: config?.analyticsGtmId,
};
TagManager.initialize(tagManagerArgs);
}
const mainContentParts = (
typeof config?.customFooter === 'string'
? config.customFooter

View file

@ -1,4 +1,5 @@
import { useEffect } from 'react';
import TagManager from 'react-gtm-module';
import { useRecoilState, useSetRecoilState } from 'recoil';
import { LocalStorageKeys } from 'librechat-data-provider';
import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
@ -98,4 +99,11 @@ export default function useAppStartup({
setAvailableTools({ pluginStore, ...mapPlugins(tools) });
}, [allPlugins, user, setAvailableTools]);
if (startupConfig?.analyticsGtmId) {
const tagManagerArgs = {
gtmId: startupConfig?.analyticsGtmId,
};
TagManager.initialize(tagManagerArgs);
}
}