Solved

Google Analytics

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Editing .asp website 5 35
run powershell script endlessly 3 32
how to properly reinitialize tinyMCE rich text html editor 8 18
Today Date 3 13
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Concerto Cloud Services, a provider of fully managed private, public and hybrid cloud solutions, announced today it was named to the 20 Coolest Cloud Infrastructure Vendors Of The 2017 Cloud  (http://www.concertocloud.com/about/in-the-news/2017/02/0…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

710 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