1

I have a test server (Amazon EC2). I have many websites running on it using tomcat. I want to analyze a website using google analytics. My website url is http://my.website.com:8080/site/. I have setup a google analytics account. But google doesn't allow me to enter this website name in Property settings as Default url, but when I remove the port number it allows me http://my.website.com/site/.

Now I have pasted the tracking code in my project files. But I cannot see any analytics in my google analytics account.

I have researched a lot on this. Also gone through this Getting Google Analytics to see a test server but couldn't understand.

Please guide me through this.

Community
  • 1
  • 1
Grahesh Parkar
  • 1,017
  • 1
  • 13
  • 16

2 Answers2

1

You should use port 80 not 8080, than your url will be http://my.website.com/site/.

You can set port number in tomcat config file server.xml, or if you have more http services on server, use proxy server (i.e nginx).

k.nieszporek
  • 135
  • 2
  • 12
  • I have some other service running on port 80. – Grahesh Parkar May 16 '14 at 14:57
  • So, as I wrote, you should use proxy. I suggest nginx as proxy server http://nginx.org/. – k.nieszporek May 16 '14 at 15:07
  • what if I use this method. http://www.puschitz.com/InstallingTomcat.html#RelayingHTTPPort – Grahesh Parkar May 17 '14 at 09:22
  • If you use iptables to redirect the port, You will not be able to use it for other services running on port 80, if you are using apache it stop work correctly, because the whole traffic will be redirected to Tomcat. Nginx in your case is the best solution I know. If you don't want use nginx maybe this will help http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html. – k.nieszporek May 17 '14 at 17:41
0

With Universal Analytics, you could try the following:

/** load google analytics **/
(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','http://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-YY', 'auto');
ga('set', 'checkProtocolTask', function(){}); // Removes failing protocol check. @see: http://stackoverflow.com/a/22152353/1958200
ga('require', 'displayfeatures');
ga('send', 'pageview');

It should remove the problem with non-matching ports by passing an empty function into checkProtocolTask. You should be able to continue on port 8080.

This trick also works well for Google Chrome extensions.

dvdsmpsn
  • 2,839
  • 1
  • 26
  • 40