Beautiful Open-Source Form Builder
fix: Update iframe detection logic and GTM initialization
JhumanJe57e14a34227
diff --git a/client/composables/useIsIframe.js b/client/composables/useIsIframe.jsindex 07c330d7b..a879b4994 100644--- a/client/composables/useIsIframe.js+++ b/client/composables/useIsIframe.js@@ -1,6 +1,6 @@export const useIsIframe = () => {if (import.meta.client) {- return window.location !== window.parent.location || window.frameElement+ return window.location !== window.parent.location || (window.frameElement !== null)}return false}diff --git a/client/plugins/gtm.client.js b/client/plugins/gtm.client.jsindex d2c8c338e..d236f8441 100644--- a/client/plugins/gtm.client.js+++ b/client/plugins/gtm.client.js@@ -1,30 +1,32 @@-import gtmConfig from '../gtm'-export default defineNuxtPlugin(() => {const route = useRoute()const isIframe = useIsIframe()const isPublicFormPage = route.name === 'forms-slug'// Only enable GTM if not in a form page (for respondents) and not in an iframe- if (!isPublicFormPage && !isIframe && process.env.NUXT_PUBLIC_GTM_CODE) {+ if (!isPublicFormPage && !isIframe) {// Initialize GTM manually only when neededconst gtm = useGtm()// Override the enabled setting to true for this session- gtmConfig.enabled = true+ gtm.enable(true)++ // Initialize Consent Mode+ window.dataLayer = window.dataLayer || []+ function gtag() {+ window.dataLayer.push(arguments)+ }- // Watch for route changes to track page views- watch(() => route.fullPath, () => {- if (!route.name || route.name !== 'forms-slug') {- gtm.trackView(route.name, route.fullPath)- }- }, { immediate: true })+ gtag('consent', 'default', {+ 'ad_storage': 'denied',+ 'analytics_storage': 'granted',+ 'functionality_storage': 'granted',+ 'security_storage': 'granted'+ })++ // Enable IP anonymization+ gtag('set', 'anonymize_ip', true)- return {- provide: {- gtm- }- }}return {}