Skip to content

Conversation

bydawen
Copy link
Contributor

@bydawen bydawen commented Jun 5, 2025

Open edX forum post with a proposal of the feature:
https://discuss.openedx.org/t/add-gtm-support-to-open-edx-core/16234

Added GTM support to enable easier integration of analytics and tracking scripts. Making it more flexible for platform operators to manage tags via the site configuration panel in the admin section of the platform:

admn_pnl

If Google Tag Manager ID configured correctly it will appear on the website with corresponding GTM scripts initialisations:

lms_legacy

Also we made PR to enable similar support on the MFE parts of edX platform:
frontend-platform

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

openedx-webhooks commented Jun 5, 2025

Thanks for the pull request, @bydawen!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Jun 5, 2025
@bydawen bydawen marked this pull request as draft June 5, 2025 10:21
Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

I know this still a draft, just some early feedback. Before submitting for review, make sure to link this to supporting documentation such as a product proposal, relevant github issues, linked PRs, etc.

Comment on lines 446 to 448
##### GOOGLE TAG MANAGER IDS #####
GOOGLE_TAG_MANAGER_ID = AUTH_TOKENS.get('GOOGLE_TAG_MANAGER_ID')

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
##### GOOGLE TAG MANAGER IDS #####
GOOGLE_TAG_MANAGER_ID = AUTH_TOKENS.get('GOOGLE_TAG_MANAGER_ID')

Either the default value will come in from common.py, or a custom value will be set in the LMS_CFG YAML file. This line would have no effect and should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you totally correct, this is completely unnecessary now. Thank you for advice!

@bydawen bydawen force-pushed the rg/gtm-support branch 2 times, most recently from 01bc5df to f2ba4cd Compare June 6, 2025 11:37
@bydawen
Copy link
Contributor Author

bydawen commented Jun 6, 2025

I know this still a draft, just some early feedback. Before submitting for review, make sure to link this to supporting documentation such as a product proposal, relevant github issues, linked PRs, etc.

Hi @kdmccormick, thank you for the review and remarks.

For this PR, I forgot to mark it as a draft before submitting — my apologies for that.

My colleague created a forum post about GTM integration to gather feedback and start a discussion. I've also pinned the link at the top of the PR description:
https://discuss.openedx.org/t/add-gtm-support-to-open-edx-core/16234

@bydawen bydawen marked this pull request as ready for review June 6, 2025 11:50
@igobranco
Copy link
Contributor

IMO you should also add GTM environment configuration.

Example:

What I want to highlight is the possibility to have custom GTM environments. This is important when you have to manage a complex configuration on GTM. Like test it before on DEV/STAGE environments before publishing to production. Just view our implementation and be inspired by it!

Copy from my comment on Open edX Forum: https://discuss.openedx.org/t/add-gtm-support-to-open-edx-core/16234/5

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

A couple requests. I'm also checking with my team on whether this needs a Product Proposal or whether the forum post is sufficient.

@@ -177,6 +177,15 @@
</script>
% endif

<% gtm_id = static.get_value("GOOGLE_TAG_MANAGER_ID", getattr(settings, "GOOGLE_TAG_MANAGER_ID", None)) %>
Copy link
Member

@kdmccormick kdmccormick Jun 10, 2025

Choose a reason for hiding this comment

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

Suggested change
<% gtm_id = static.get_value("GOOGLE_TAG_MANAGER_ID", getattr(settings, "GOOGLE_TAG_MANAGER_ID", None)) %>
<% gtm_id = static.get_value("GOOGLE_TAG_MANAGER_ID", settings.GOOGLE_TAG_MANAGER_ID) %>

There is no reason to use getattr when we are certain that settings.GOOGLE_TAG_MANAGER_ID will at least be defined with a default value of None. In fact, it is harmful to use getattr, because it would silence errors in the case where "GOOGLE_TAG_MANAGER_ID" is typo'd, renamed, or removed.

This applies in general when writing Python -- always prefer accessing the attribute directly, only use getattr when absolutely necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, fixed

################### GOOGLE TAG MANAGER ##################
# .. setting_name: GOOGLE_TAG_MANAGER_ID
# .. setting_default: None
# .. setting_description: The container ID for Google Tag Manager,
Copy link
Member

Choose a reason for hiding this comment

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

Please explain more. Why would I set this? What does it do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made a more detailed description of these settings.
Thank you for review!

@feanil
Copy link
Contributor

feanil commented Jun 10, 2025

Is it possible to use the site theming capability to insert this instead? See the comment on your discourse post: https://discuss.openedx.org/t/add-gtm-support-to-open-edx-core/16234/5?u=feanil

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

See @feanil ' s comment. I can see the community need for an easy way to configure GTM, but this is part of a general problem (adding configurable JS snippets) and we'd rather not continue adding vendor-specific settings into edx-platform unless absolutely necessary.

@bydawen
Copy link
Contributor Author

bydawen commented Jun 11, 2025

Is it possible to use the site theming capability to insert this instead? See the comment on your discourse post: https://discuss.openedx.org/t/add-gtm-support-to-open-edx-core/16234/5?u=feanil

Hi @feanil, I’ve replied on the forum post about this. In short, the main reason behind our approach is to keep the implementation minimal.

@kdmccormick
Copy link
Member

keep the implementation minimal.

The minimal implementation is the one which does not add any new code :) Using site theming does not add any new code that needs to be maintained, but adding a new one-off setting and vendor-specific JS does.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Jun 12, 2025
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
Projects
Status: In Eng Review
Development

Successfully merging this pull request may close these issues.

5 participants