Skip to content

Commit

Permalink
Datalayer was not pushed when container was disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed May 22, 2024
1 parent 1f6a01d commit ea82c64
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Frontend/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ public function enqueue_datalayer_content(): void {
$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-container' ], GTMKIT_VERSION, [ 'in_footer' => false ] );
$dependency = ( $this->options->get( 'general', 'container_active' ) && apply_filters( 'gtmkit_container_active', true ) )
? [ 'gtmkit-container' ]
: [ 'gtmkit' ];

wp_register_script( 'gtmkit-datalayer', '', $dependency, GTMKIT_VERSION, [ 'in_footer' => false ] );
wp_enqueue_script( 'gtmkit-datalayer' );
wp_add_inline_script( 'gtmkit-datalayer', apply_filters( 'gtmkit_datalayer_script', $script ), 'before' );
}
Expand Down

0 comments on commit ea82c64

Please sign in to comment.