diff --git a/readme.txt b/readme.txt index dca5cac..7d382d4 100644 --- a/readme.txt +++ b/readme.txt @@ -97,6 +97,7 @@ Find out about what's new in our [our release post](https://gtmkit.com/gtm-kit-1 #### Enhancements: #### Bugfixes: +* Fix missing datalayer when using Google Consent Mode default settings. #### Other: diff --git a/src/Frontend/Frontend.php b/src/Frontend/Frontend.php index 2c95916..91ee0f6 100644 --- a/src/Frontend/Frontend.php +++ b/src/Frontend/Frontend.php @@ -83,6 +83,7 @@ public function enqueue_settings_and_data_script(): void { ?> window.gtmkit_settings = ; window.gtmkit_data = ; + window.datalayer_name ); ?> = window.datalayer_name ); ?> || []; options->get( 'general', 'gcm_default_settings' ) ) : ?> if (typeof gtag === "undefined") { function gtag(){datalayer_name ); ?>.push(arguments);} @@ -111,8 +112,7 @@ public function enqueue_datalayer_content(): void { $datalayer_data = apply_filters( 'gtmkit_datalayer_content', [] ); - $script = 'window.' . esc_js( $this->datalayer_name ) . ' = window.' . esc_js( $this->datalayer_name ) . ' || [];' . "\n"; - $script .= 'const gtmkit_dataLayer_content = ' . wp_json_encode( $datalayer_data ) . ";\n"; + $script = 'const gtmkit_dataLayer_content = ' . wp_json_encode( $datalayer_data ) . ";\n"; $script .= esc_attr( $this->datalayer_name ) . '.push( gtmkit_dataLayer_content );' . "\n"; wp_register_script( 'gtmkit-datalayer', '', [], GTMKIT_VERSION, [ 'in_footer' => false ] );