Solved

Google Analytics

Posted on 2014-04-16
4
130 Views
Last Modified: 2016-02-24
Can I just insert the following javascript code in the header of the webpage:

 <script language="JavaScript" src="js/googleanalytics.js" type="text/javascript"></script>

instead of this

  (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-xxxxxxx-1', 'yourdomain.com');
  ga('send', 'pageview');
0
Comment
Question by:Scott Huffman
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Murfur earned 500 total points
ID: 40006217
Assuming you have edited the js file adding your analytics UA-key and domain, and the path to the file on your server is correct, then yes!

Dare I ask why?
0
 

Author Comment

by:Scott Huffman
ID: 40006305
Thanks MurFur - I was just trying to keep the code on the website simple.  Instead of inserting the google code on each page - I just wanted to add the script call from the javascripts that I already have.
0
 
LVL 11

Expert Comment

by:Murfur
ID: 40006376
Neat & tidy is a good thing - any changes to the GA code means only one file to edit rather than every page. Good idea!
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40010571
I agree with keeping it in one spot.  I do the same. However, if you are using any serverside code like asp or php, it is petter to through it in some type of common include file.  The reason is less http calls.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question