ember-fastboot / fastboot-app-server

A production-ready app server for running Ember FastBoot apps
140 stars 74 forks source link

script tag in index.html #90

Open matthias-k opened 5 years ago

matthias-k commented 5 years ago

Hi,

we are in the process of enabling our ember app for fastboot. So far it works very well when using ember serve, but it's not yet working with fastboot-app-server: We have a script tag in our index.html to load google analytics as suggested from google at https://developers.google.com/analytics/devguides/collection/analyticsjs/

<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
</script>
<!-- End Google Analytics -->

When using ember server we can then later on access the ga object as window.ga but when accessing the page via fastboot-app-server, this results in TypeError: window.ga is not a function. Can you help me fix this or just indicate where I missed something in the docs? I would be very grateful for your help!

abhinavk96 commented 4 years ago

Any updates/work-around for this?

snewcomer commented 4 years ago

In general you need to worry about accessing window on node in a running app will error. One option is to block the ga function call if window is not present