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

fix: youtube race condition when GTM loads #33649

Merged

Conversation

viadanna
Copy link
Contributor

@viadanna viadanna commented Nov 2, 2023

Description

The changes fix an issue with YouTube videos when Google Analytics is used. It prevents the video XBlock from properly loading YouTube videos.

It's caused by a race condition, in which both Open edX and GTM implement onYouTubeIframeAPIReady and run already existing implementations of this callback.

The issue arises when GTM overwrites it, as the callback implemented by Open edX expects a resolve() attribute that isn't implemented by GTM. This change ensures the original global is used by Open edX so it's never overwritten.

Testing instructions

Testing

  1. Set up a devstack/instance with this branch and Google Analytics.
  2. Navigate to a Unit containing a YouTube video and open your browser Development Tools.
  3. Add the following breakpoint:
    image
  4. Reload the page and wait a couple of seconds before pressing F8 to continue running. This ensures that onYouTubeIframeAPIReady is overwritten by GTM.
  5. Make sure the YouTube video loads correctly.
  6. Disable the breakpoint and reload, again making sure the Youtube video loads when the callback set by Open edX is used.

Deadline

"None"

Other information

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 2, 2023
@openedx-webhooks
Copy link

Thanks for the pull request, @viadanna! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@mphilbrick211
Copy link

Hi @viadanna! Just flagging that there are some failing checks. Would you mind taking a look?

@viadanna
Copy link
Contributor Author

Sure thing @mphilbrick211

@viadanna
Copy link
Contributor Author

@mphilbrick211 There was a problem with the testing infrastructure, can you restart the unit-tests workflow?

image

@mphilbrick211
Copy link

Hi @viadanna! I'm looking into this for you.

@mphilbrick211 mphilbrick211 added the waiting for eng review PR is ready for review. Review and merge it, or suggest changes. label Nov 20, 2023
@mphilbrick211
Copy link

Hi @viadanna! All looks OK now, so I'm marking this as ready for review.

@pomegranited
Copy link
Contributor

Hi @viadanna @mphilbrick211 may I review/merge this PR as CC?

@viadanna
Copy link
Contributor Author

Sure thing @pomegranited

@pomegranited
Copy link
Contributor

@viadanna Which Jira ticket is this issue for?

@viadanna
Copy link
Contributor Author

@pomegranited BB-7904 (private)

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I wasn't able to reproduce the actual race condition (on master), but race conditions can be hard to reproduce. Instead, I verified that this change does not break videos or GA4 analytics.

  • I tested this using the PR test instructions.
  • I read through the code.
  • I checked for accessibility issues N/A
  • Includes documentation N/A
  • User-facing strings are extracted for translation N/A

@ArturGaspar
Copy link
Contributor

👍

  • I tested this: I checked that GTM is being loaded with the key provided in settings, and tested according to the PR instructions and checked that the video works with or without setting the breakpoint
  • I read through the code
  • I checked for accessibility issues - N/A
  • Includes documentation - N/A
  • I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository. - N/A

@pomegranited pomegranited merged commit 7d01394 into openedx:master Feb 5, 2024
65 checks passed
@pomegranited pomegranited deleted the viadanna/fix-gtm-race-condition branch February 5, 2024 23:08
@openedx-webhooks
Copy link

@viadanna 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U waiting for eng review PR is ready for review. Review and merge it, or suggest changes.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants