Adding Javascript to a Subdomain

Hi friends,

We need to add Intercom and Hubspot Javascript to one subdomain, how can we go about this with Cloudflare?

For reference, here are the lines of code we need to add;

<script>

  window.intercomSettings = {
    app_id: "*****"
  };
</script>

<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/qyau07fy';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();</script>

<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/4287822.js"></script>
<!-- End of HubSpot Embed Code -->

Thanks everyone!

If you want to use Cloudflare for that you will have to enable paid workers and add this via a worker script.

Not sure thats the best approach though, simply add it to your site on your server :slight_smile:

Thanks! How would we structure this worker?

That’s where we’re lost.

Something of that sort might work

Dude you can solve this the CF-Way or the native way…

Pls do whatever you like but you should srsly consider implementing it the native way. Go to the Subdomain and add it to the HTML or include it as a file in the header.
You can use workers for this but this is the lazy way and you would have to paid for and just gaining something you could do yourself with less to no effort

This topic was automatically closed after 14 days. New replies are no longer allowed.