Topic: Best way to embed stats tracking code?

First off, I'm sorry I'm not too php savvy.

I use Reinvigorate and Google Analytics for my stats. They both do different things well so I tend to use both at the same time.

Reinvigorate says the javascript should be put before </head> and Google wants to be right before </body>. I was just wondering what file(s) I should be putting this code in.

I think it should be a feature or extension to be able to paste any stats code into a text box somewhere in the administration.



Also with both services you can track registered users. I was wondering what code I should use to get the current logged-in user's username. Here's the example of the code I've been using with Ning.

<?php
$user = XN_Profile::current();
echo "$user->fullName";
?>

What would be the punbb version of this? Thanks!




Google:

<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("*****");
pageTracker._initData();
pageTracker._trackPageview();
pageTracker._setVar("<?php
$user = XN_Profile::current();
echo "$user->fullName";
?>");
</script>

Reinvigorate:

<script type="text/javascript" src="http://include.reinvigorate.net/re_.js"></script>
<script type="text/javascript">
// <![CDATA[
var re_name_tag = "<?php
$user = XN_Profile::current();
echo "$user->fullName";
?>";
re_("******");
// ]]>
</script>

Re: Best way to embed stats tracking code?

NetworkShadow wrote:

I think it should be a feature or extension to be able to paste any stats code into a text box somewhere in the administration.

Extension.

NetworkShadow wrote:

Also with both services you can track registered users. I was wondering what code I should use to get the current logged-in user's username. Here's the example of the code I've been using with Ning.

<?php
$user = XN_Profile::current();
echo "$user->fullName";
?>

What would be the punbb version of this? Thanks!

<?php echo $forum_user['username']; ?>
Carpe diem

Re: Best way to embed stats tracking code?

Thanks for the code. I was close when I was peeking at the php code.

I've tried the Google Analytics extension, but it doesn't install. I guess I'll just have to wait... Plus it doesn't sound like you can use any custom stats scripts with that extension.

4 (edited by kierownik 2008-07-25 11:17)

Re: Best way to embed stats tracking code?

offcource not, otherwise I would have called it something else smilewink

That it does not install can be wright, I am going to change it after everything goes online for sure and not for beta versions.

Re: Best way to embed stats tracking code?

Anatoly wrote:
<?php echo $forum_user['username']; ?>

This doesn't seem to be working; I put the stats javascript into the announcement box... I assume it doesn't support php. Should I edit the header.php to add the stats code? What's the best way to do this until there is an extension? Thanks.