0

I was wondering why google does not offer simpler and shorter way of initializing ga.js code like this:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-Y']);
  _gaq.push(['_trackPageview']);
</script>
<script src="//google-analytics.com/ga.js" async="true" type="text/javascript"></script>

Original solution is to make use of javascript check for protocol, set async flag etc, etc..

Are there any downsides to my solution?

1

1 Answer 1

0

Client's browser may not support the async attribute. Google's code by dynamically creating script tag will load the script asynchronously anyway. If the code is not loaded asynchronously the user may have bad experience. Imagine that in the user's country Google is blocked by the government and the user uses browser which does not supports async. If this happens the user's page will block until http://google-analytics.com/ga.js timeout, which may take a while...

For further reading on this topic I can recommend you:

  1. http://www.phpied.com/non-onload-blocking-async-js/
  2. http://www.amazon.com/gp/product/B008CQA8BA/
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.