Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working with an outside software vendor to add Google Analytics code to their web app, so that we can track its usage. Their developer suggested that we place the code in an external ".js" file, and he could include that in the layout of his application.

The StackOverflow question "Google Analytics: External .js file covers the technical aspect, so apparently tracking is possible via an external file.

However, I'm not quite satisfied that this won't have negative implications. Does including the tracking code as an external file affect the statistics collected by Google?

share|improve this question
up vote 2 down vote accepted

Why would the location of the code affect the statistics? Whether you make an XHR request using inline JavaScript or a function call to an external library makes no difference to the browser, much less the server your request is directed at.

share|improve this answer
I come from a PHP background, where an included file sees a different set of pre-defined environment variables than the script that includes it. Just wanted to make sure Javascript didn't have any similar side effects. – Jacob Hume Feb 17 '11 at 22:26

As long as the code runs, Google won't care whether it's in-line or not.

share|improve this answer

Your Answer


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.