Changing the Google Analytics Key

The legacy iac.org site was instrumented using Google Analytics. Each Google Analytics site is assigned a unique key; the key that identifies the legacy site, UA-2593170-18, is under the control of the EAA IT department. Because we continue to serve the old content while the new site is under construction, and because we want the ability to track site usage, I created a new key: UA-8063403-10.

The next step was to change the key in all of the legacy HTML files, which was accomplished with the following shell script:

sudo apt-get install ed
cd /var/www/old-site
find members public -name "*.html" | while read f
do
   ed $f << EOFEOF
   /UA-2593170-18/s//UA-8063403-10/
   w
   q
   EOFEOF
done

This worked fine except for files in the public/forms directory, which never had Google Analytic scripts installed in the first place. Those files were edited as follows:

cat > /tmp/eds

/<\/head>/i
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-8063403-10']);
  _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>
.
w
q
[ctrl-d]

cd public/forms
for f in *
do
  echo $f; ed "$f" < /tmp/eds
done