GA: remove @next/third-parties/google

This commit is contained in:
Enrico Ros
2025-02-17 22:12:21 -08:00
parent ad96d6ce66
commit 6629585b32
5 changed files with 69 additions and 27 deletions
-20
View File
@@ -21,7 +21,6 @@
"@mui/joy": "^5.0.0-beta.51",
"@mui/material": "^5.16.14",
"@next/bundle-analyzer": "^15.1.7",
"@next/third-parties": "^15.1.7",
"@prisma/client": "~5.22.0",
"@t3-oss/env-nextjs": "^0.12.0",
"@tanstack/react-query": "^5.66.5",
@@ -1783,19 +1782,6 @@
"node": ">= 10"
}
},
"node_modules/@next/third-parties": {
"version": "15.1.7",
"resolved": "https://registry.npmjs.org/@next/third-parties/-/third-parties-15.1.7.tgz",
"integrity": "sha512-wDAh/gW+WFT7jPYmGEGtNeLC74D8+hu3S6YJOpcfC/6uBMSC7yjh0QW1/RPYKziVnjqe6O4jR0AhbN0uuS8CZw==",
"license": "MIT",
"dependencies": {
"third-party-capital": "1.0.20"
},
"peerDependencies": {
"next": "^13.0.0 || ^14.0.0 || ^15.0.0",
"react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0"
}
},
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@@ -9392,12 +9378,6 @@
"b4a": "^1.6.4"
}
},
"node_modules/third-party-capital": {
"version": "1.0.20",
"resolved": "https://registry.npmjs.org/third-party-capital/-/third-party-capital-1.0.20.tgz",
"integrity": "sha512-oB7yIimd8SuGptespDAZnNkzIz+NWaJCu2RMsbs4Wmp9zSDUM8Nhi3s2OOcqYuv3mN4hitXc8DVx+LyUmbUDiA==",
"license": "ISC"
},
"node_modules/through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
-1
View File
@@ -32,7 +32,6 @@
"@mui/joy": "^5.0.0-beta.51",
"@mui/material": "^5.16.14",
"@next/bundle-analyzer": "^15.1.7",
"@next/third-parties": "^15.1.7",
"@prisma/client": "~5.22.0",
"@t3-oss/env-nextjs": "^0.12.0",
"@tanstack/react-query": "^5.66.5",
+1 -2
View File
@@ -1,5 +1,4 @@
import React from 'react';
import { sendGAEvent } from '@next/third-parties/google';
import type { SxProps } from '@mui/joy/styles/types';
import { Box, Button, Step, stepClasses, StepIndicator, stepIndicatorClasses, Stepper, Typography } from '@mui/joy';
@@ -14,7 +13,7 @@ import { AgiSquircleIcon } from '~/common/components/icons/AgiSquircleIcon';
import { ChatBeamIcon } from '~/common/components/icons/ChatBeamIcon';
import { ShortcutKey, useGlobalShortcuts } from '~/common/components/shortcuts/useGlobalShortcuts';
import { animationTextShadowLimey } from '~/common/util/animUtils';
import { hasGoogleAnalytics } from '~/common/components/GoogleAnalytics';
import { hasGoogleAnalytics, sendGAEvent } from '~/common/components/GoogleAnalytics';
import { useIsMobile } from '~/common/components/useMatchMedia';
import { useUIContentScaling } from '~/common/state/store-ui';
+67 -1
View File
@@ -1,5 +1,5 @@
import * as React from 'react';
import { GoogleAnalytics as NextGoogleAnalytics } from '@next/third-parties/google';
import Script from 'next/script';
export const hasGoogleAnalytics = !!process.env.NEXT_PUBLIC_GA4_MEASUREMENT_ID;
@@ -8,6 +8,72 @@ export function getGA4MeasurementId(): string | null {
return process.env.NEXT_PUBLIC_GA4_MEASUREMENT_ID || null;
}
export function sendGAEvent(..._args: Object[]) {
if (currDataLayerName === undefined)
return console.warn('[DEV] GA has not been initialized yet');
if (window[currDataLayerName])
window[currDataLayerName]?.push(arguments);
else
console.warn('[DEV] GA dataLayer does not exist');
}
//
// Google Analytics implementation
// Taken from Vercel: https://github.com/vercel/next.js/blob/b996171654f8ae25b7409dc7a0f27d5217abf35e/packages/third-parties/src/google/ga.tsx
//
// defined during the first render
let currDataLayerName: 'dataLayer' | undefined = undefined;
declare global {
// noinspection JSUnusedGlobalSymbols
interface Window {
dataLayer?: Object[];
}
}
/**
* This has been adapted from Vercel, with:
* - removal of the performance.mark and useEffect
* - removal of custom dataLayer name
*/
function NextGoogleAnalytics(props: {
gaId: string
debugMode?: boolean
nonce?: string
}) {
const { gaId, debugMode, nonce } = props;
if (currDataLayerName === undefined)
currDataLayerName = 'dataLayer';
return (
<>
<Script
id='_next-ga-init'
dangerouslySetInnerHTML={{
__html: `
window['${currDataLayerName}'] = window['${currDataLayerName}'] || [];
function gtag(){window['${currDataLayerName}'].push(arguments);}
gtag('js', new Date());
gtag('config', '${gaId}' ${debugMode ? ',{ \'debug_mode\': true }' : ''});`,
}}
nonce={nonce}
/>
<Script
id='_next-ga'
src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}
nonce={nonce}
/>
</>
);
}
/**
* Note: we are using this third-party component from Vercel which is very experimental
* and has just been launched weeks back (at the time of writing this code). There could
+1 -3
View File
@@ -1,6 +1,4 @@
import { sendGAEvent } from '@next/third-parties/google';
import { hasGoogleAnalytics } from '~/common/components/GoogleAnalytics';
import { hasGoogleAnalytics, sendGAEvent } from '~/common/components/GoogleAnalytics';
import type { DModelsService, DModelsServiceId } from '~/common/stores/llms/llms.service.types';
import { DLLM, LLM_IF_HOTFIX_NoTemperature, LLM_IF_OAI_Chat, LLM_IF_OAI_Fn } from '~/common/stores/llms/llms.types';