Skip to content

Commit

Permalink
Load the datalayer after the container
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed May 4, 2024
1 parent 13d4172 commit 3ef6cc1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Frontend/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ 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_VERSION, [ 'in_footer' => false ] );
wp_register_script( 'gtmkit-datalayer', '', [ 'gtmkit-container' ], 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 Expand Up @@ -182,7 +182,7 @@ function (cb) {

$script = ob_get_clean();

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

0 comments on commit 3ef6cc1

Please sign in to comment.