ga.js
check out this Google Analytics Documentation.
If you use a relative link like below, you don't need the https detection part of the script.
Also note that the -151
is from my advanced mod_rewrite Fix for Caching Updated Files. So you won't need that unless you implement that technique.
Here is an updated shell script that fetches the latest ga.js file from google and places it in the folder of your site.
#!/bin/sh # TMP DIRECTORY MYTMP=/tmp/ # SAVE ga.js HERE INSTALL_IN=/web/user/askapache.com/z/j/ # RESOURCE URLS GOOGLE_GA_URL=http://www.google-analytics.com/ga.js # USER-AGENT UA="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3" # CD TO TMP DIRECTORY cd $MYTMP # DOWNLOAD THE FILE curl --header "Pragma:" -f -s -A "${UA}" -m 1800 --retry 15 --retry-delay 15 --max-redirs 8 -O $GOOGLE_GA_URL # GIVE FILE CORRECT PERMISSIONS chmod 644 $MYTMP/ga.js # COPY FILE TO SITE DIRECTORY cp -r $MYTMP/ga.js $INSTALL_IN # RETURN TO OLDPWD cd $OLDPWD exit 0;
Just add this to your crontab by typing crontab -e
where google-analytics-update.sh is the location of your shell script.
@daily /web/user/scripts/google-analytics-update.sh >/dev/null 2>&1