Is Open edX compatible with Google Analytics 4 ? Will GOOGLE_ANALYTICS_ACCOUNT support a “G-” ID instead of a “UA-” ID ?
Since I got no answer, I set up a new instance and used Google Analytics 4 with it. It does not seem to work as I cannot even see the realtime users connected to my new instance.
I make a workaround for Google Analytics 4 .
Add the code below into lms / templates /main.html :
<% ga_acct1 = static.get_value(“GOOGLE_ANALYTICS_ACCOUNT_4”, settings.GOOGLE_ANALYTICS_ACCOUNT_4) %>
% if ga_acct1 == ‘PRO’:
< script >
window.dataLayer = window.dataLayer || ;
gtag(‘js’, new Date());
< / script >
Add a line into lms / envs /production.py:
GOOGLE_ANALYTICS_ACCOUNT_4 = AUTH_TOKENS.get(‘GOOGLE_ANALYTICS_ACCOUNT_4’)
Add a line into /edx/etc/lms.yml:
GOOGLE_ANALYTICS_ACCOUNT_4 : ‘PRO’
Because I am not good at JS . Maybe somebody could share a better way to support Google Analytics
I’ll give it a try the next time I work on my Test environment with Koa. Thanks.