Warning: Illegal string offset '_imagedir' in /home/cakephpf/public_html/lofiversion/index.php on line 545

Warning: Illegal string offset '_emodir' in /home/cakephpf/public_html/lofiversion/index.php on line 546
CakePHP UnOfficial Community Forum > Analytics Tracker
Help - Search - Member List - Calendar
Full Version: Analytics Tracker
CakePHP UnOfficial Community Forum > Tutorials Galore

Terminal13
Because I always want to tracker my visitors, but also the ones without Javascript I created this simple element to include the Analytics code at any time.

The script is based on an existing script explained here.

/app/view/elements/analytics.ctp
[php] ?>
<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('<?php e($adsense_key); ?>');
pageTracker._initData();
pageTracker._trackPageview();
</script>
<noscript>
<?php
$var_utmac = $adsense_key;
$var_utmhn = $_SERVER['SERVER_NAME'];
$var_utmn = rand(1000000000,9999999999);
$var_cookie = rand(10000000,99999999);
$var_random = rand(1000000000,2147483647);
$var_today = time();
$var_referer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '-';
$var_uservar='-';
$var_utmp='/jstracker' . $_SERVER['REQUEST_URI'];
$urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=3&utmn=' . $var_utmn . '&utme=&utmcs=-&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' . $var_utmhn . '&utmhid=' . $var_utmn . '&utmr=' . $var_referer . '&utmp=' . $var_utmp . '&utmac=' . $var_utmac . '&utmcc=__utma%3D' . $var_cookie . '.' . $var_random . '.' . $var_today . '.' . $var_today . '.' . $var_today . '.2%3B%2B__utmz%3D' . $var_cookie . '.' . $var_today . '.2.2.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D' . $var_cookie . '.' . $var_uservar . '%3B';
e(' <img src="' . $urchinUrl . '" border="0" />');
?>
</noscript>
<?php [/php]

/app/views/layouts/default.ctp (or any other layout)
[php]
// place this right before the </body> tag
e($this->element('analytics', array($adsense_key)));
[/php]

/app/app_controller.php
[php]
// place this inside beforeFilter()
// and change the value to your analytics code
$this->set('adsense_key', 'this_is_your_key');
[/php]

Although this isn't really a tutorial I hope this will help you all out biggrin.gif

Terminal13
Stickymaddness
That's pretty cool, nice one! biggrin.gif

I sure this will come in handy for a few people!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.
Lo-Fi 1.1 iDS Beta, Originally written by Matt,
re-written by Shaun Harrison, Layer 04.com, for pre IPB2.0 versions.