Skip to content

Commit

Permalink
Merge pull request #278 from appsembler/bugfix/gtm-with-video-measure…
Browse files Browse the repository at this point in the history
…ment-breaks-video-load

Add a timeout delay prior to GTM init to fix intermittent YouTube video module loading problems
  • Loading branch information
bryanlandia authored Jul 7, 2023
2 parents 2c4a1e3 + 57438dc commit e6cc775
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit e6cc775

Please sign in to comment.