How to setup FeedBurner Stats on Drupal
Sat, 04/05/2008 - 6:47am — Schoonzie
I just setup FeedBurner Stats tracking code on this blog and had a few problems with the Drupal code that FeedBurner supplies. The main problem is that it doesn't get the proper page URL when put into a block.
I just setup FeedBurner Stats tracking code on this blog and had a few problems with the Drupal code that FeedBurner supplies. The main problem is that it doesn't get the proper page URL when put into a block.
Putting javascript tracking codes in blocks has a number of benefits, the main ones being that you can use the block visibility settings to show it only for specific user roles (eg - not site administrators).
The code that Feedburner provide is:
<script src="http://feeds.feedburner.com/~s/yourfeedburnername?i=http://yoursite.com<?php print $node_url ?>" type="text/javascript" charset="utf-8"></script>
This code will work properly if placed in the Node.tpl.php file in your theme directory - which isn't a great option because
- It's hard to limit the roles that are tracked and
- It will only show on node pages and not any other system pages or views
- Not everyone has access to the theme files and wants to mess around with them
Here is the modified code that will work when placed in a block.
<script src="http://feeds.feedburner.com/~s/yourfeedburnername?i=http://www.yoursite.com/<?php print $_REQUEST['q'] ?>" type="text/javascript" charset="utf-8"></script>
The code is by no means perfect but it does the job. If you are not using clean URLs (who isn't these days) you may want to add ?q= after yoursite.com/ otherwise the URLs in FeedBurner Stats won't match up correctly to the URLs on your site.
Trackback URL for this post:
http://www.schoonzie.com/trackback/26


Comments
'Widgets'
I created a content type 'widgets'. I then created a feedburner widget, and a statcounter widget and a google analytics widget. Then I created a View for this content type and provided a block. That block is then only displayed for unauthenticated and non-admin roles.
Hi Paul, That seems like a
Hi Paul,
That seems like a lot of effort for such a small thing. Why not just put all the code into one block?
Addendum to previous
Addendum to previous comment: Which means I've obviously not really been looking at my stats in detail to see that I'm missing a lot of information.
url function
This type of functionality is exactly what the url() function is for. This would eliminate the clean url's issue, and also let you track the aliased path rather than the standard drupal path.
Here's the updated code:
<script src="http://feeds.feedburner.com/~s/yourfeedburnername?i=<?php print url($_GET['q'], NULL, NULL, TRUE) ?>" type="text/javascript" charset="utf-8"></script>
The additional arguments for the url parameter are necessary so that the url printed will be absolute.
Hi Roger, I was thinking of
Hi Roger,
I was thinking of doing this but I ended up deciding against it because I wanted to know whether people were accessing the pages from their system path (node/x) or their aliased path. If that is not an issue for you, then I agree that your code would be more suitable.
FeedBurner module
Or use the excellent FeedBurner module: http://drupal.org/project/feedburner
FeedBurner module
I installed the FeedBurner module and it doesn't look like it has stats functionality yet. I think that is still a future plan.
Welcome to enter (wow gold)
Welcome to enter (wow gold) and (wow power leveling) trading site, (Rolex) are cheap, (World of Warcraft gold) credibility Very good! Quickly into the next single! Key words directly to the website click on transactions!
Post new comment