Using Google Analytics with Dragonfly

June 20, 2008

Though Google Analytics does support dynamic pages, it is a little more prickly about implementation. After you have created a new web site profile, follow these steps.

1. Open your favorite UTF-8 compliant text/html editor. I highly recommend the freeware known as Notepad2 .

2. Start a new file to be named “analyticstracking.php ” and insert the following code
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-0000000-0 ");
pageTracker._initData(); pageTracker._trackPageview('');
</script>
<?php
// End Analytics tracking code
?>

Replacing UA-0000000-0 with your own ID number.

Save and upload (or use FTP) to your server.

2. Open your root index.php in the UTF-8 compliant editor. Near line 140 will be the file include for the footer file. Right before the footer include, add the following lines

$virtual_page = "name=".$pagetitle;
include_once "analyticstracking.php";

Save and upload (or use FTP) to your server.

3. Analytics should confirm that data is being received within ten minutes – just check every other minute until it catches.

Notes:
a. Analytics only shows up to the previous day, so you will not be able to immediately verify that it is indeed working.
b. If you replace your index.php file, you will have to re-insert the appropriate coding as this is not a Dragonfly feature.
c. If you would prefer to not track your own visits, the quickest method is replacing the index.php code with this:

if(!is_admin()) {
$virtual_page = "name=".$pagetitle;
include_once "analyticstracking.php";
} else {
echo "Google Analytics Disabled for Admins";
}

Change or remove the text Google Analytics Disabled for Admins if you want.

You can view the stats of Erythisis Designs from when I created a alternate profile to test this fix out.
Sample Stats Resulting from Trick

Share |

Leave a Comment

CommentLuv Enabled

Spam Protection by WP-SpamFree