Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a timeout delay prior to GTM init to fix intermittent YouTube video module loading problems #278

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lms/templates/partials/analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@
}];
</script>
% endif
## Add a timeout delay to GTM initialization to avoid breaking video module loading from YouTube
## with Google Analytics v<4 with Measure Videos turneed on
## see: https://discuss.openedx.org/t/first-video-on-lesson-dont-work/3836/3
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
<script>const loadGTM = function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${customer_gtm_id | n, js_escaped_string}');</script>
};setTimeout(loadGTM.bind(null, window,document,'script','dataLayer','${customer_gtm_id | n, js_escaped_string}'), 1000);</script>
<!-- End Google Tag Manager -->
% endif

Expand Down
Loading