Solved

Google Analytics

Posted on 2014-04-16
4
127 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now