-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👌 IMPROVE: delay push after load event
This is helpful to handle privacy policies framework choices before GTM data is pushed. Signed-off-by: Mickaël Perrin <[email protected]>
- Loading branch information
1 parent
faac69d
commit ac19446
Showing
2 changed files
with
12 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
@if($enabled) | ||
<script> | ||
function gtmPush() { | ||
@unless(empty($dataLayer->toArray())) | ||
window.dataLayer.push({!! $dataLayer->toJson() !!}); | ||
@endunless | ||
@foreach($pushData as $item) | ||
window.dataLayer.push({!! $item->toJson() !!}); | ||
@endforeach | ||
} | ||
addEventListener("load", gtmPush); | ||
</script> | ||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ $id }}" | ||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | ||
@endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters