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

Introduce timeout for scripts such as Zendesk, Hubspot and defer GTM #2088

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions mitxpro/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
{% block extrahead %}
{% endblock %}
{% endspaceless %}
{% if zendesk_config.help_widget_enabled and not request.path|startswith:'/certificate/' %}
<script defer id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key={{zendesk_config.help_widget_key}}"> </script>
{% endif %}
</head>
<body class="{% block bodyclass %}{% endblock %}">
<div class="main-panel">
Expand All @@ -61,18 +58,28 @@
{% block scripts %}
{% endblock %}
{% if zendesk_config.help_widget_enabled and not request.path|startswith:'/certificate/' %}
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
<script defer type="text/javascript">
function loadZendesk(){
var script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'ze-snippet';
script.async = true;
script.src = "https://static.zdassets.com/ekr/snippet.js?key={{zendesk_config.help_widget_key}}";
document.getElementsByTagName("body")[0].appendChild(script);
if (typeof zE !== 'undefined') {
zE('webWidget', 'prefill', {
name: {
value: '{{user.name}}',
},
email: {
value: '{{user.email}}',
}
});
zE('webWidget', 'prefill', {
name: {
value: '{{user.name}}',
},
email: {
value: '{{user.email}}',
}
});
}
}

document.addEventListener('DOMContentLoaded', function() {
setTimeout("loadZendesk();", 3000)
});
</script>
{% endif %}
Expand Down
25 changes: 12 additions & 13 deletions mitxpro/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,25 @@ <h2>Contact Us</h2>
<ul class="footer-nav">
<li><a href="/about-us/">About Us</a></li>
</ul>
<script
defer
charset="utf-8"
type="text/javascript"
src="//js.hsforms.net/forms/v2-legacy.js"
></script>
<script
defer
charset="utf-8"
type="text/javascript"
src="//js.hsforms.net/forms/v2.js"
></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
function loadHubspot(){
var v2_lagacy_script = document.createElement('script');
v2_lagacy_script.type = "text/javascript"
v2_lagacy_script.src = "//js.hsforms.net/forms/v2-legacy.js"

var v2_script = document.createElement('script');
v2_script.type = "text/javascript"
v2_script.src = "//js.hsforms.net/forms/v2.js"

if (typeof hbspt !== "undefined") {
hbspt.forms.create({
portalId: "{{ hubspot_portal_id }}",
formId: "{{ hubspot_footer_form_guid }}",
});
}
}
document.addEventListener('DOMContentLoaded', function() {
setTimeout("loadHubspot();", 3000)
});
</script>
</div>
Expand Down
2 changes: 1 addition & 1 deletion mitxpro/templates/partials/gtm_head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if APIKEYS.GTM_TRACKING_ID %}
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
<script defer>(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);
Expand Down