Skip to content

Commit

Permalink
Fix missing datalayer when using Google Consent Mode default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Dec 4, 2023
1 parent d49023a commit 0407ba1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions src/Frontend/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function enqueue_settings_and_data_script(): void {
?>
window.gtmkit_settings = <?php echo wp_json_encode( apply_filters( 'gtmkit_header_script_settings', $settings ), JSON_FORCE_OBJECT ); ?>;
window.gtmkit_data = <?php echo wp_json_encode( apply_filters( 'gtmkit_header_script_data', [] ), JSON_FORCE_OBJECT ); ?>;
window.<?php echo esc_js( $this->datalayer_name ); ?> = window.<?php echo esc_js( $this->datalayer_name ); ?> || [];
<?php if ( $this->options->get( 'general', 'gcm_default_settings' ) ) : ?>
if (typeof gtag === "undefined") {
function gtag(){<?php echo esc_attr( $this->datalayer_name ); ?>.push(arguments);}
Expand Down Expand Up @@ -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 ] );
Expand Down

0 comments on commit 0407ba1

Please sign in to comment.