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

analytics: remove Google Analytics in favor of Google Tag Manager #343

Closed
VeraZab opened this issue Oct 29, 2019 · 14 comments
Closed

analytics: remove Google Analytics in favor of Google Tag Manager #343

VeraZab opened this issue Oct 29, 2019 · 14 comments

Comments

@VeraZab
Copy link

VeraZab commented Oct 29, 2019

As per conversation here: https://github.com/plotly/marketing-team/issues/118#issuecomment-542334742

We'd like to put the Google Tag Manager script into our dash-sample-apps instead of using GA only.

GTM includes such tracking codes like Pardot, which the marketing team would find useful to add on the apps.

Paste this code as high in the <head> of the page as possible:

<!-- 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-N6T2RXG');</script>
<!-- End Google Tag Manager -->

Additionally, paste this code immediately after the opening <body> tag:

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N6T2RXG"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
@ycaokris
Copy link
Contributor

ycaokris commented Nov 7, 2019

We have an app-loading problem in executing gunicorn app:server after inserting above script in app.index_string.

#351 modifies predeploy.py to add the following content inside app.py right above if __name__ == "__main__":

app.index_string = '''<!DOCTYPE html>
<html>
    <head>
    {%metas%}
        <title>{%title%}</title>
        {%favicon%}
        {%css%}
        <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-N6T2RXG');</script>
    </head>
    <body>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N6T2RXG"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
        {%app_entry%}
        <footer>
            {%config%}
            {%scripts%}
            {%renderer%}
        </footer>
    </body>
</html>
'''

This has successfully loaded the script inside app. When I run python app.py locally, script in is being loaded, and tracked by pardot.

Screen Shot 2019-11-07 at 4 23 26 PM

Screen Shot 2019-11-07 at 4 26 22 PM

However running gunicorn app:server has resulted in app fail loading, and we noticed that all dash_renderer loading js has been wrongly replaced by this index string(screenshot below).

Screen Shot 2019-11-07 at 4 30 48 PM

Screen Shot 2019-11-07 at 3 57 06 PM

This problem doesn't exist with running before editing index_string. I'm not sure whether it's a deployment-only issue, or related with dash-render, will further investigate with @Marc-Andre-Rivet or @byronz

@shammamah-zz
Copy link
Contributor

Funnily enough, I'm running into this issue as well when I try to run my dash_bio integration tests locally.

@ycaokris
Copy link
Contributor

ycaokris commented Nov 7, 2019

Updates

The app loading problem we had above with gunicorn is not due to insertion of index string. We define a env variable export DASH_APP_NAME=dash-drug-precursor before gunicorn app.py and it turned out this env has caused app error. Once this variable is cleared, app could be loaded without any problem. Verified by running the same workflow with apps not changed.

Here with gunicorn command, script and body has been inserted with GTM script we want

Screen Shot 2019-11-07 at 5 07 01 PM

@ycaokris
Copy link
Contributor

#353 deployed on https://dash-playground.plotly.host/dash-drug-discovery/ for a functional check.

@lundstrj
Copy link
Contributor

@VeraZab @ycaokris bump. Is this still a relevant issue we should keep around or has the world already moved on past it?

@VeraZab
Copy link
Author

VeraZab commented Dec 10, 2019

well, I haven't had a chance to test this working, @ycaokris , is this ready to test on gallery?

@VeraZab
Copy link
Author

VeraZab commented Dec 10, 2019

personally, i still see the old analytics code on our gallery apps, do we have an estimate of when i could test the new gtm tag?

@ycaokris
Copy link
Contributor

well, I haven't had a chance to test this working, @ycaokris , is this ready to test on gallery?

Not for batch deploy yet due to gallery sizing limit, I've ran manually for oil-and-gas and drug discovery and blocked by disk space issue. https://github.com/plotly/streambed/issues/13854 needs to be ran rather than manual deploy, will be worked on today and I'll update when all gal apps are re-deployed.

@lundstrj
Copy link
Contributor

Sounds like it's still relevant. Let's see if we can get it across the finish line.

@ycaokris
Copy link
Contributor

ycaokris commented Dec 18, 2019

Updates on this issue:

With #366 , we've updated new GA tag for 31/49 python apps on gallery.

Still needs to work on:

  1. Two remaining python apps not yet merged in the dash-sample-app
    This should be auto-enabled when we complete merging all PRs WIP.

#135
#368

  1. 13 Dash-bio apps from https://github.com/plotly/dash-bio, @josegonzalez

  2. Two dashr app: NCBI-Explorer and Uber NYC Rasterizer.
    Right now inserting index string in dashR app hasn't been enabled (see https://github.com/plotly/streambed/issues/11962). I'm not sure whether asset loading as GA.js

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-N6T2RXG')

would make it work so we may not get it in header, instead, will be in footer. Talked with @rpkyle and he'll test it out.

@ycaokris
Copy link
Contributor

ycaokris commented Jan 13, 2020

Follow up on this issue:

With #366 , we've updated new GA tag for 31/49 python apps on gallery.

Still needs to work on:

  1. Two remaining python apps not yet merged in the dash-sample-app
    This should be auto-enabled when we complete merging all PRs WIP.

#135
#368

All non-bio python apps have been merged and GA tag up-to-date.

  1. 13 Dash-bio apps from https://github.com/plotly/dash-bio, @josegonzalez

Gallery updates for bio apps will be completing within this week.

  1. Two dashr app: NCBI-Explorer and Uber NYC Rasterizer.
    Right now inserting index string in dashR app hasn't been enabled (see plotly/streambed#11962). I'm not sure whether asset loading as GA.js
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-N6T2RXG')

would make it work so we may not get it in header, instead, will be in footer.

Currently work-in-progress by @HammadTheOne in #395

@ycaokris ycaokris assigned HammadTheOne and unassigned rpkyle Jan 28, 2020
@ycaokris
Copy link
Contributor

Updated status on GTM tag on gallery apps:

@lundstrj
Copy link
Contributor

lundstrj commented Feb 4, 2020

Is this connected to https://github.com/plotly/marketing-team/issues/148?

@ycaokris
Copy link
Contributor

ycaokris commented Feb 5, 2020

All gallery apps except dash-R done. Closing this in favor of progress track in https://github.com/plotly/marketing-team/issues/148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants