[ index ]
|
For this example we imagine the worst case, a site of plain html files that have to be handled individually and we have to insert that snippet of tracking code into each file just before the </head> tag. The plan is to use the find command to walk us through the website one file at a time and then use the ed command to insert our code where we want it to appear.
In the top level directory of the website we need to make three small files to help us out. First we copy our tracking code into a file:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-######-1"; urchinTracker(); </script> Note that you need to replace the UA-######-1 with your own website's tracking code.Next we will need a set of instructions for ed:
/<\/HEAD> -1r tracking.txt w qThose four little lines will save us a lot of work. The line /<\/HEAD> tells ed to go the first occurence of a line containing the closing </head> tag. (That is a case-sensitive search so if you need to, change it to /<\/head> instead.) The next line,
Finally we need a shell script to pull it all together for us:
#!/bin/sh
for FILE in `find . -name "*.html" -print`
do
ed $FILE < ed.cmd
done
At the Unix command prompt enter "sh install_tracking.sh". That's what I did and now my site is ready to reap the benefits of all those cool reports available from Google Analytics.2006-04-05 16:03:21
©2010 Echo3 Online Services, LLC