I have several sites running off a single DotNetNuke installation and I wanted to add the Google Analytics Javascript to several of the sites. I had a few options:
- I could change default.aspx to include the JavaScript code in the HTML head
- I could incorporate the Urchin Javascript in a DNN Skin
- I could go I could go into each pages Page Settings>Advanced Settings>Page Header Tags and drop the JavaScript into the textbox
- Just run a SQL statement
Option 1 does not work because all installations would have the same JavaScript and I could not be site specific with the Google Analytics Site ID. Option 2 is probably the best option but I am lazy and did not want to update each skin and upload them each to the site. Option 3 is just ridiculous for a few of our larger sites and would take forever...so, I picked Option 4, the quick sql statement:
UPDATE Tabs SET PageHeadText = '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>'
WHERE (PortalID = 0)
Before you use this sql update statement against your DNN database, make sure you update your Google Analytics ID, "UA-xxxxxx-x", and PortalID #.
This will automatically change all pages for that portal to include the Google Urchin JavaScript. If you do not want certain pages such as the Admin pages to include this JavaScript, simply filter out any by ParentID's
Example:
UPDATE Tabs SET PageHeadText = '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>'
WHERE (PortalID = 0) AND ParentID <> '38'
You could easily use this same script to add other HTML head code. Hope that helps!