Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Google Analytics provide this snippet of code to copy and paste to a site:

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxxxxxx-1', 'mysite.com');
  ga('send', 'pageview');

</script>

But the a and m variables used in the function signature are not used throughout the code at all. Is it safe to remove them? I can't see any negative implications that could arise, and I don't understand why Google put them in the first place (i.e. their code minification tools should have probably removed them in the first place).

share|improve this question

migrated from webapps.stackexchange.com Aug 6 '13 at 4:54

This question came from our site for power users of web applications.

add comment

1 Answer 1

up vote 3 down vote accepted

I see a and m being used.

.insertBefore(a,m)
share|improve this answer
    
You are right. Resharper marked them as unused, at first glance I also didn't see them and trusted Resharper too much. I'll file a bug report to Resharper. Thanks! –  Ofer Zelig Aug 6 '13 at 0:59
2  
Resharper might be getting confused because a and m aren't actually passed to the function (7 parameters declared, but only 5 arguments passed). But they are declared inside the function - it's a quick/compact way of declaring local variables without having to explicitly specify var. –  w3d Aug 6 '13 at 14:36
    
"But they are declared inside the function" - I should perhaps have used the word initialised here, since they are declared in the function prototype. –  w3d Aug 6 '13 at 16:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.