Speed Up Google Analytics




http://www.howtoforge.com/speed_up_google_analytics


Speed Up Google Analytics
This method uses crontab to execute a shell script that downloads an
updated urchin.js file every 24 hours and saves it into your local
sites directory. Thats it!
The problem occurs when google-analytics.com/urchin.js is requested by
billions of web users all over the world at one time, it can cause
your sites pages to load at a snails pace. Especially if you are using
WordPress or a similar CMS.

Official Google Position on locally hosting urchin.js
Setup crontab by typing
crontab -e
at a unix-style command prompt (ssh) then add:
11 12 * * * /home/user/websites/urch.sh >/dev/null 2>&1
Shell script example:
#!/bin/sh
rm /home/user/websites/askapache.com/z/j/urchin.js
cd /home/user/websites/askapache.com/z/j/
wget http://www.google-analytics.com/urchin.js
chmod 644 /home/user/websites/askapache.com/z/j/urchin.js
cd ${OLDPWD}
exit 0;
There are 2 pretty major things that you accomplish by hosting
urchin.js locally:


1. You Enable persistant connections

2. You ensure that the correct 304 Not Modified header is sent back to
your site visitors instead of reserving the entire file.

One problem with remote hosted urchin.js is the server that the
urchin.js file is served from does not allow persistant connections.
Another big big reason is that even though Cache-Control headers are
correctly set by google-analytics when serving urchin.js, instead of
responding to an If-Modified-Since header correctly with a 304 Not
Modified header, indicating the file has not been modified, google-
analytics instead returns the entire urchin.js file again, thus
rendering the cache-control void.
You can see this problem clearly with a wireshark capture.
GET /urchin.js HTTP/1.1
Accept: */*
Referer: http://www.askapache.com
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
If-Modified-Since: Tue, 20 Mar 2007 22:49:11 GMT
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SU
2.011; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Alexa Toolbar; .NET CLR
3.0.04506.30)
Host: www.google-analytics.com
Connection: Keep-Alive

HTTP/1.1 200 OK
Cache-Control: max-age=604800, public
Content-Type: text/javascript
Last-Modified: Tue, 20 Mar 2007 22:54:02 GMT
Content-Encoding: gzip
Server: ucfe
Content-Length: 5675
Date: Sat, 24 Mar 2007 18:23:12 GMT
Note: You will need a caching scheme on your server for optimum
results.
Pretty sweet bit of overkill!

.



Relevant Pages

  • Re: Terminal type and Cron
    ... |>>I added a new task in the Crontab scheduler and everytime it runs I ... |>>The task is a shell script I wrote that runs a report generator to ... |>The usual way is to set it in a shell script executed by cron: ... |>One way to make sure you get a realistic set of environment variables is to ...
    (comp.unix.sco.misc)
  • Re: /etc/crontab does not exist but Leopard now runs cronjob
    ... Archive and Install. ...  My cronjobs, as I expected, stopped running. ... You didn't mention anything about a shell script in ~/bin when you asked ... Someone else has already asked about crontab -l. ...
    (comp.sys.mac.system)
  • Re: cron job emailing drive space?
    ... >> thread or a Google keyword selection that yields better results, ... one has to know what components to use to write the shell script ... Well, OK, it doesn't "crash" per se, but Apache stops responding ... > If you are replying from google groups do not use its default way ...
    (comp.os.linux.misc)
  • Re: How to insert command in crontab using shell
    ... > How do insert command in crontab .For example ... > I want to write a shell script that will able to insert data in cron. ... Please, read the man page, notice these funny lines oddly scattered ... Now, believe me, you don't really want to modify your crontab ...
    (comp.unix.shell)
  • Re: Help in Crontab Shell Script?
    ... I wanted to write a shell script with Crontab & cron. ... command and read up on the meaning of the various ...
    (comp.os.linux.misc)