Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Google Analytics

Posted on 2014-04-16
4
Medium Priority
?
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Murfur earned 2000 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 53

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

722 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