Skip to content

Commit

Permalink
Merge pull request #29 from humanmade/use-window-datalayer
Browse files Browse the repository at this point in the history
Check for existing window.dataLayer, append if found.
  • Loading branch information
roborourke authored May 30, 2022
2 parents ab59419 + cf1efe9 commit fc7d14e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function get_gtm_tag( string $container_id, array $data_layer = [], string $data

if ( ! empty( $data_layer ) ) {
$tag .= sprintf(
'<script>var %1$s = [ %2$s ];</script>',
'<script>window.%1$s = window.%1$s || []; window.%1$s.push([ %2$s ]);</script>',
$data_layer_var,
wp_json_encode( $data_layer )
);
Expand Down

0 comments on commit fc7d14e

Please sign in to comment.