Playing Nice with ShortStat
MT, TXP, or WP, whichever acronym you choose to use for your blogging needs you should be able to get it to work with ShortStat. (Except for Stan—but don’t worry, ShortStan 1.0 is almost ready for beta testing.) Since the most frequently asked question I recieve about ShortStat is, “I can’t get it to work with XYZ” (what is this, Jeopardy?) I thought I’d write a quick how-to.
First make sure that the obvious has been accounted for: your database config is set up properly, your include path is pointing to a file that actually exists and that ShortStat is turned on ($shortstat
should be set to true
in /shortstat/configuration.php).
MoveableType
No rules, just throw the ShortStat include anywhere. (Note: I’m not sure if this is true with MT PHP. Anyone have any experience with this?)
Textpattern
The ShortStat include must come after the textpattern();
function call in each of your section files. (Illuminated by Jon Hicks.)
WordPress
The ShortStat include must come after the wp-blog-header.php
include. (Tip courtesy of Seth Thomas Rasmussen.)
025 Comments
The real question is when is the new version of shortstat going to be ready for public consumption?
…And for the last time, it’s TXP, not TP! I’m using Textpattern right, not Toilet Paper. ;)
Duly noted but allow me for the last time to say, it’s “ShortStat,” not “ShortStats” or “Short Stats.” It’s “short” because there’s no “s” at the end, get it? Good. ;)
(Not that anyone in this thread spelled it wrong but I’ve see it more than enough.)
Oops sorry Ryan, didn’t mean to ignore your question. The way things are going, by the end of the year. I’m of a mind to under-promise and over-deliver though so don’t be surprised if it’s sooner.
No problem, Shaun.
I’ve got the opposite problem (over promise, under deliver) going with my little project (TypeSpace). I was hoping to have it out the door around around a month and a half ago, and it’s still not ready to go. I’ve just got way too much going on right now (including a bunch of stuff that I had no idea was going to happen when I threw the mid Sept. ETA)… Hopefully I learned a lesson, though I’m not sure what it is. ;)
Perfect timing for this post! Tonight, I am implementing ShortStat on my WordPress-powered site.
The one thing that I was going to request is that you post a full version of the latest Short Stat in the meantime so that people don’t have to install the older version and then find the update and run it. That exact problem is what has kept me from installing it until now. But I hear the software is just so damn good that I just have to have it.
Yeah, just thought I’d give some feedback.
Hmm…
The ShortStat include is the very first item in my WordPress template, which means it comes before the wp-blog-header.php include, and I haven’t noticed any problems with ShortStat because of it.
What problems have been seen from having ShortStat included before the WordPress code?
Shaun, does the inc.stats.php file still call
die()
when it cannot access the database? I personally find this quite unacceptable; why would you stop showing the contnets of the file, if the stats are not working?I changed it to a simple
if
clause:and that change requires that the database connection function returns
true
on success andfalse
on failure.I also put the
include
statement at the end of the pages, as then the user is already reading the page and wouldn’t care more about if the stats is taking somewhat longer.Janne, I’ve commented out the die() statements in v0.35b and handled things a bit differently in what will be the 1.0 release.
That’s a good point about putting the include at the end of the page but the time it takes to run ShortStat is really negligible (unless your server is excruciatingly slow). The next major version of ShortStat uses cookies and JavaScript to track some additional data that isn’t available to through PHP so it must be included before any data is sent to the browser (unless you decide to disable the new features).
This sucks, I am always on the back burner. I want my ShortStan.
Ryan Berg, The problem I had is that if the ShortStat include came before the wp-blog-header.php include, that page would not be listed individually in the Resources column of ShortStat. All the other stats appeared to work beautifully, and I still had number reflective of the total hits being displayed at the top of the Resources column, but nothing about how many times specific resources were getting accessed.
If you aren’t having this issue, then a) I feel sheepish, and b) I wonder what little detail was causing me grief… :
I wonder if someone knows how to get it working on IPB forums (Invision Power Board, version 1.2). The template admin modules don’t allow any direct php, so it’d have to go in a certain spot in a certain file.
Does anyone know what that spot is, or does someone have a better way?
Seth,
My ShortStat doesn’t appear to be having that problem. You can take a look for yourself at My ShortStat Page.
Akaxaka,
Simply put it somewhere in the PHP instead of the templates. I’m running ShortStat on one of my sites and have also installed it on a phpBB2 forum without any problems. I don’t know IPB’s PHP structure, but just drop the include line in the PHP that makes up the footer of every page.
Shaun, while the code works beautifully, I have one suggestion to make. My error logs keep getting PHP Notices from ShortStat. The same error keeps popping up, saying that variable X is undefined. A copy of my error log can be found here. This can easily be solved by using this syntax to retrieve variables:
$var = (isset($_GET['var_name'])) ? $_GET['var_name'] : '';
It’s not a serious problem, but it does help you maintain good coding practices.
Mr. Berg,
Would you mind posting(or emailing) part of one of your site templates that includes ShortStat as well as WordPress? I am curious to compare and contrast it with my setup so as to get to the bottom of this. I would not be surprised if my rearranging of the include calls was merely coincidental. I can share my template setup as well and perhaps we can both figure some things out…
Ryan and I spoke after he posted this, and we agreed on the following: As long as the ShortStat include is, well, included on every page, it doesn’t really matter where in
index.php
you call it (as long as it is run). It could be run before thewp-blog-header.php
include, after thewp-blog-header.php
, and I am pretty sure that you can even run it from withinwp-blog-header.php
! If the last option is true, I would say that it is probably the best option, as it keeps yourindex.php
file nice and clean.Then my issue must be related to the script I run at the start of every page:
Before the
n
in the line preceding//xml processing instruction
is where the xml prolog goes, but it gets edited out by Shaun’s blog software.Anyhoo, I know this for certain: The first three lines are 1) Include script above; 2) Include wp-blog-header.php; 3) Include ShortStat … and if I switch 2 and 3, that page will not record hits in the resources column. Everything else works as intended, I believe, though I don’t know if that file no longer registers hits in general either. I don’t know enough about ShortStat.
Similarly, I don’t know what would cause this conflict…
Here you go, Seth. This is the very top of my index.php file.
Well hrmm… like I say, I’m not sure what the deal is then. Perhaps something with declaring headers in my _init script, and then something that happens in the WP include ends up conflicting with ShortStat if it is included before WP??? I’m not terribly savvy with PHP, so if anybody can shed some light on this, I’ll send you hohos.*
*By hohos I mean no hohos at all.
Has anyone got this working with Expression Engine? I dropped the php include at the top of my index file and it doesn’t seem to be recording anything. Thanks for nay info.
i am not sure why the link before isn’t working, anyways, this link works in case you need to look at the code (follow the “all blogs” link)
My Site
[quote] The ShortStat include must come after the textpattern(); function call in each of your section files. [/quote]
Hmm, this doesn’t work for me. If I include the code before the textpattern(); function, then it works alright!
I tried to get ShortStat to run with MT PHP. No go so far. I’m getting an error message from the Smarty engine saying it can’t connect to the database through localhost. That’s the problem, my database isn’t located at localhost. The script works perfectly on regular PHP pages though (I’m running as PHP-CGI on Dreamhost). I only get an error in Dynamic PHP Movable Type pages.
Mike, I’m assuming you have the appropriate values set in
configuration.php
since it’s working elsewhere. I just did a little digging andmysql_pconnect()
defaults tolocalhost
if no server name is passed to it. Add this code to one of the pages and see if the$SI_db
array is missing:Shoot me an email, we’ll solve it off thread and then post the solution here.
Shaun, you absolutely rock.
Thanks for being so completely transparent and awesome. I’m learning so much from you.