Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Address PR comments

Carlos Monastyrskifd813e7dbd20
diff --git a/frontend/index.html b/frontend/index.html
index d1441cf6ca..2266b7180e 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -8,11 +8,11 @@
http-equiv="Content-Security-Policy"
content="
default-src 'self';
- script-src 'self' https://*.posthog.com https://js.stripe.com https://api.stripe.com https://widget.intercom.io https://js.intercomcdn.com https://hcaptcha.com https://*.hcaptcha.com 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net/npm/@lottiefiles/[email protected]/dist/dotlottie-player.wasm;
+ script-src 'self' https://*.posthog.com https://js.stripe.com https://api.stripe.com https://widget.intercom.io https://js.intercomcdn.com https://hcaptcha.com https://*.hcaptcha.com https://www.googletagmanager.com 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net/npm/@lottiefiles/[email protected]/dist/dotlottie-player.wasm;
style-src 'self' 'unsafe-inline' https://hcaptcha.com https://*.hcaptcha.com;
child-src https://api.stripe.com;
- frame-src https://js.stripe.com/ https://api.stripe.com https://www.youtube.com/ https://hcaptcha.com https://*.hcaptcha.com;
- connect-src 'self' wss://nexus-websocket-a.intercom.io https://api-iam.intercom.io https://api.heroku.com/ https://id.heroku.com/oauth/authorize https://id.heroku.com/oauth/token https://checkout.stripe.com https://app.posthog.com https://*.posthog.com https://api.stripe.com https://api.pwnedpasswords.com http://127.0.0.1:* https://hcaptcha.com https://*.hcaptcha.com https://cdn.jsdelivr.net/npm/@lottiefiles/[email protected]/dist/dotlottie-player.wasm;
+ frame-src https://js.stripe.com/ https://api.stripe.com https://www.youtube.com/ https://hcaptcha.com https://*.hcaptcha.com https://www.googletagmanager.com;
+ connect-src 'self' wss://nexus-websocket-a.intercom.io https://api-iam.intercom.io https://api.heroku.com/ https://id.heroku.com/oauth/authorize https://id.heroku.com/oauth/token https://checkout.stripe.com https://app.posthog.com https://*.posthog.com https://api.stripe.com https://api.pwnedpasswords.com http://127.0.0.1:* https://hcaptcha.com https://*.hcaptcha.com https://www.googletagmanager.com https://cdn.jsdelivr.net/npm/@lottiefiles/[email protected]/dist/dotlottie-player.wasm;
img-src 'self' https://static.intercomassets.com https://js.intercomcdn.com https://downloads.intercomcdn.com https://*.stripe.com https://i.ytimg.com/ data:;
media-src 'self' https://js.intercomcdn.com;
font-src 'self' https://fonts.intercomcdn.com/ https://fonts.gstatic.com;
diff --git a/frontend/src/hooks/useGtm.ts b/frontend/src/hooks/useGtm.ts
deleted file mode 100644
index d1f5d4748d..0000000000
--- a/frontend/src/hooks/useGtm.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import { useEffect } from "react";
-
-const GTM_ID = "GTM-WL5C7MWT";
-const GTM_SCRIPT_ID = "gtm-script";
-const GTM_NOSCRIPT_ID = "gtm-noscript";
-
-const CLOUD_HOSTNAMES = ["app.infisical.com", "eu.infisical.com", "us.infisical.com"];
-
-const isCloudHostname = () => CLOUD_HOSTNAMES.includes(window.location.hostname);
-
-/**
- * Loads GTM only on Infisical Cloud pre-auth pages.
- * Cleans up GTM scripts on unmount (when navigating to authenticated pages).
- */
-export const useGtm = () => {
- useEffect(() => {
- if (!isCloudHostname()) return undefined;
-
- // Inject noscript iframe
- const noscript = document.createElement("noscript");
- noscript.id = GTM_NOSCRIPT_ID;
- const iframe = document.createElement("iframe");
- iframe.src = `https://www.googletagmanager.com/ns.html?id=${GTM_ID}`;
- iframe.height = "0";
- iframe.width = "0";
- iframe.style.display = "none";
- iframe.style.visibility = "hidden";
- noscript.appendChild(iframe);
- document.head.insertBefore(noscript, document.head.firstChild);
-
- // Inject GTM script
- const script = document.createElement("script");
- script.id = GTM_SCRIPT_ID;
- script.async = true;
- script.src = `https://www.googletagmanager.com/gtm.js?id=${GTM_ID}`;
- document.head.insertBefore(script, document.head.firstChild);
-
- return () => {
- document.getElementById(GTM_SCRIPT_ID)?.remove();
- document.getElementById(GTM_NOSCRIPT_ID)?.remove();
- };
- }, []);
-};
diff --git a/frontend/src/hooks/useGtm.tsx b/frontend/src/hooks/useGtm.tsx
new file mode 100644
index 0000000000..dba51665f9
--- /dev/null
+++ b/frontend/src/hooks/useGtm.tsx
@@ -0,0 +1,39 @@
+import { useEffect } from "react";
+import { Helmet } from "react-helmet";
+
+import { isInfisicalCloud } from "@app/helpers/platform";
+
+const GTM_ID = "GTM-WL5C7MWT";
+const GTM_NOSCRIPT_ID = "gtm-noscript";
+
+export const GtmHead = () => {
+ const shouldLoad = isInfisicalCloud();
+
+ useEffect(() => {
+ if (!shouldLoad) return undefined;
+
+ // Inject noscript iframe into body
+ const noscript = document.createElement("noscript");
+ noscript.id = GTM_NOSCRIPT_ID;
+ const iframe = document.createElement("iframe");
+ iframe.src = `https://www.googletagmanager.com/ns.html?id=${GTM_ID}`;
+ iframe.height = "0";
+ iframe.width = "0";
+ iframe.style.display = "none";
+ iframe.style.visibility = "hidden";
+ noscript.appendChild(iframe);
+ document.body.insertBefore(noscript, document.body.firstChild);
+
+ return () => {
+ document.getElementById(GTM_NOSCRIPT_ID)?.remove();
+ };
+ }, [shouldLoad]);
+
+ if (!shouldLoad) return null;
+
+ return (
+ <Helmet>
+ <script async src={`https://www.googletagmanager.com/gtm.js?id=${GTM_ID}`} />
+ </Helmet>
+ );
+};
diff --git a/frontend/src/pages/middlewares/restrict-login-signup.tsx b/frontend/src/pages/middlewares/restrict-login-signup.tsx
index 59ef9faba4..b78e86e70e 100644
--- a/frontend/src/pages/middlewares/restrict-login-signup.tsx
+++ b/frontend/src/pages/middlewares/restrict-login-signup.tsx
@@ -12,7 +12,7 @@ import { SessionStorageKeys } from "@app/const";
import { useServerConfig } from "@app/context";
import { authKeys, fetchAuthToken } from "@app/hooks/api/auth/queries";
import { setAuthToken } from "@app/hooks/api/reactQuery";
-import { useGtm } from "@app/hooks/useGtm";
+import { GtmHead } from "@app/hooks/useGtm";
const QueryParamsSchema = z.object({
callback_port: z.coerce.number().optional().catch(undefined),
@@ -22,7 +22,6 @@ const QueryParamsSchema = z.object({
export const AuthConsentWrapper = () => {
const { config } = useServerConfig();
- useGtm();
const [hasConsented, setHasConsented] = useState(() => {
const consentInfo = sessionStorage.getItem(SessionStorageKeys.AUTH_CONSENT);
if (!consentInfo) {
@@ -52,6 +51,7 @@ export const AuthConsentWrapper = () => {
return (
<>
+ <GtmHead />
{config.authConsentContent && !hasConsented && (
<div className="bg-opacity-90 fixed inset-0 z-50 flex items-center justify-center bg-mineshaft-700/80">
<div className="max-h-[80vh] w-4/12 overflow-y-auto rounded-lg bg-bunker-800 p-6 text-white">