If youre using Google Analytics (GA) with GTM but notice page load times creeping up due to multiple tags firing on every scroll event
heres a simple tweak:
Use conditional loading for your GA snippet in the Data Layer. This way, it only fires when necessary.
// In an HTML Template tag<script>dataLayer = window. dataLayer || [];function gtag(){data_layer. push(arguments);}gtag('js', new Date());</script><!-- Only load this script if certain conditions are met -->{%if (pagePath '/thank-you' or pageEvents. includes(scroll)) %}<iframe src=" height=0 width=1 style='display:none;visibility:hidden'></iframe>{% endif %}This reduces unnecessary tag firing, making your site load faster while still collecting valuable data.
Faster page loads + better analytics? Yes please!Pro tip: Use the GTM Debugger to identify which tags are slowing things down and adjust accordingly.
-
>Remember - every millisecond counts in a user's experience!✅ Reduced Load Time
✔ Improved User Experience