KunalM
KunalM5mo ago

Google Tag Manager on Marimo

To install GTM on a webpage, the following code needs to be injected just under <head> <!-- Google Tag Manager --> <script>(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','GTM-***');</script> <!-- End Google Tag Manager --> Is there a clean way to do this in Marimo?
1 Reply
Akshay
Akshay5mo ago
The only place we allow execution of custom scripts is through anywidget. You could maybe achieve this through mo.ui.anywidget (its render function is called when the widget is rendered), but I'm not 100% sure. https://docs.marimo.io/guides/integrating_with_marimo/custom_ui_plugins.html#marimo.ui.anywidget If you try it, let me know how it goes?