Skip to content

Using Clickheat with CakePHP

2008 July 17

The Clickheat software, rocks. Personally I use the plugin for phpMyVisites, but I could understand anyone adopting the standalone package too.

CakePHP layouts can be setup to automatically print the most sensible url in each page it loads. This concept will work with any visitor tracking software that has a page or url attribute that is manually assigned.
To learn how and see the code, continue reading.

In /views/layouts/default.ctp;

<?php
//determine whtehr to use url (which doesnt work on homepge ) or not.
$pageUrl='';
$params=$this->params;
if(empty($params['url']['url'])) {
	//we need to concat our own url
	$pageWeSee=$params['controller'];
	//only append action if not 'info' pages ('index' is hidden in url, and should be hidden here)
	if($pageWeSee!=='info') $pageWeSee.='/'.$params['action'];
	//any parmaeterrs we should know about?
	$ps='';
	foreach( $params['pass'] as $p){
		$ps.='/'.$p;
	}//end for each
	$pageUrl=$pageWeSee.$ps;
}else{
	//oh how sweet, a fully built url for us
	$pageUrl=$params['url']['url'];
}
?>
 
<!-- phpmyvisites -->
<a href="http://www.phpmyvisites.net/" title="Free web analytics, website statistics"
onclick="window.open(this.href);return(false);"><script type="text/javascript">
<!--
var a_vars = Array();
var pagename='<?php echo $pageUrl; ?>';
 
var phpmyvisitesSite = 94;
var phpmyvisitesURL = "http://example.org/phpmyvisites/phpmyvisites.php";
//-->
</script>
<script language="javascript" src="http://example.org/phpmyvisites/phpmyvisites.js" type="text/javascript"></script>
<object><noscript><p>Free web analytics, website statistics
<img src="http://example.org/phpmyvisites/phpmyvisites.php" alt="Statistics" style="border:0" />
</p></noscript></object></a>
<!-- /phpmyvisites --> 
<script type="text/javascript" src="http://example.com/phpmyvisites/plugins/clickheat/libs/js/clickheat.js"></script><noscript><a href="http://www.labsmedia.com/index.html">Free marketing tools</a></noscript><script type="text/javascript"><!--
clickHeatSite = 93;clickHeatGroup = '<?php echo $pageUrl; ?>';clickHeatServer = 'http://example.com/phpmyvisites/plugins/clickheat/libs/clickpmv.php';initClickHeat(); //-->
</script>

The first section of code determines whether to trust the ‘url’ parameter, or build the address from controller,action,id .

The phpmyvisites and clickheat scripts both make a php call to the completed $pageURL variable.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS