Solved

Google Analytics

Posted on 2014-04-16
4
129 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 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

16 Experts available now in Live!

Get 1:1 Help Now