How to add Google Analytics Tracking Code

thumbs_up_ico0thumbs_down_ico0
Hello All,

Whats the easiest way to add the following code to every page in my site in the head section of the html?

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-177854-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

Im not sure where to start. I tried pasting this code directly to the espace javascript section but it didnt work out. Please help if you can.

Julius

thumbs_up_ico1thumbs_down_ico0

Julius -

Putting it into the eSpace's JavaScript is correct, just make sure you omit the beginning and ending script tags.

J.Ja

thumbs_up_ico0thumbs_down_ico0
Justin,

Thanks for the advice. I did omit the script tags and it still isnt showing up in the html. Is there something I need to add so that the system knows to add it to the head section?

Julius
thumbs_up_ico0thumbs_down_ico0
Julius -

You aren't going to see it in the HTML, it gets linked to as an external .js file. :)

J.Ja
thumbs_up_ico0thumbs_down_ico0
The other solution is to put it in an expression in the header of footer webblock which resides on every page.
Be sure to enclose the script in double quotes and replace existing double quotes with double-double quotes :-)

"<script type=""text/javascript"">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-177854-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>"


 

thumbs_up_ico0thumbs_down_ico0
Justin James wrote:
Julius -

You aren't going to see it in the HTML, it gets linked to as an external .js file. :)

J.Ja
 
 I also could not find it in any .js file. Do you know why?

Joop Stringer-> Using an expression, is not a good solution (for this case) since i need that code to be inside header

Best Regards

João inácio
thumbs_up_ico0thumbs_down_ico0
João Inácio wrote:
 
 I also could not find it in any .js file. Do you know why?

Joop Stringer-> Using an expression, is not a good solution (for this case) since i need that code to be inside header

Best Regards

João inácio
 
 Joao:
This script still works :-)
The one in the header is the latest 
thumbs_up_ico0thumbs_down_ico0
Hi Joop

Do you have any suggestions how to include the logged in Master user name in the Google Analytics ie as a Custom Variable key or User Defined variable.  At the moment, the User Defined variable is showing as (not set) in google analytics.

Thanks
Charles

Joop Stringer wrote:
The other solution is to put it in an expression in the header of footer webblock which resides on every page.
Be sure to enclose the script in double quotes and replace existing double quotes with double-double quotes :-)

"<script type=""text/javascript"">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-177854-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>"


 

 
 
thumbs_up_ico0thumbs_down_ico0
João Inácio wrote:
 
 I also could not find it in any .js file. Do you know why?

Joop Stringer-> Using an expression, is not a good solution (for this case) since i need that code to be inside header

Best Regards

João inácio
 

Easiest solution.

 
thumbs_up_ico0thumbs_down_ico0
Yes, I have the basic analytics working, but it does not record the Master User Name - or any other user name in the analytics data collected...
I would like to identify by high value users etc and track problems individual users have.
thumbs_up_ico0thumbs_down_ico0
Charles Hewitt wrote:
 Do you have any suggestions how to include the logged in Master user name in the Google Analytics
 
 
 To get any other information in Google Analytics, just add it to the _gaq.push function:
        _gaq.push(['_trackEvent', 'Menu', 'Main item', this.href]);
Or
        _gaq.push([ '_trackUser', 'User', UserName ] );


Check this out : https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gaq#_gaq.push
Complete explanation on how to use _gaq.push !!
thumbs_up_ico0thumbs_down_ico0
Joop Stringer wrote:
The other solution is to put it in an expression in the header of footer webblock which resides on every page.
 
 Joop,

Small (performance) addition information for this:

Put the JS in a separe webblock an include that webblock into the footer. Besides it's easier to maintain (one webblock for the GA JS code), you can also set a own caching time on it (webblock property). Oke there is a default caching in the IIS (OS defult is 30 days), but if that one isn't an option you can manipilate it by this.

Kind reagards,
Evert