Posted tagged ‘google’

Collect visitor stats using any image with the Piwik Tracking API


Piwik is an open source web analytics system in PHP and a great alternative to Google Analytics.

It offers simplified tracking via an image tracking code:

<!-- Piwik Image Tracker -->
<img src="" style="border:0" alt="" />
<!-- End Piwik -->

In some scenarios, you might not want to expose that you are using Piwik analytics, or would like to avoid loading unnecessary resources.

Let’s use the Piwik Tracking API to turn any image into a tracker. This is useful for websites, newsletter stats and email signatures alike.


You need to have a Piwik install running with administrative access. Apache is required to get a “nice” image url.

Step 1 – Setup Piwik

Create a new website in Piwik, which will contain your stats for the image. Make note of the new site ID (Visible in Settings > Websites)

Create a new user and give that user admin rights to the website. Make note of the token_auth for that user. (Under Settings > Users)

Step 2 – Get the PiwikTracker.php Tracking API

You can obtain this file by going to the following URL (Replace with your piwik install path)$IDSITE&piwikUrl=

You can also find a copy of the file here.

Step 3 – Build the tracking code
Pick an image you’d like to use, name it stats.png and put it in a folder on your web server. I am going to use this “thumbs up” clipart. Also put PiwikTracker.php in this folder.

Now, create the file stats_t.php. (Base code below) Change line 3 and 4  to your own site id and the token_auth of the user you created in step 2. Also set your Piwik URL at line 10. If you want to distinguish between multiple tracking images, you can change line 22 to have a different message. That means you can track any number of images using one site in Piwik.

    //Set the id of your piwik site here
    $idSite = 1;
    $token_auth = 'your user token here';

    //Load Piwik Tracker
    require_once 'PiwikTracker.php';

    //Set the URL path to your Piwik Installation
    $t = new PiwikTracker($idSite,'');

    //Auth to allow for more API functions

    //Set correct IP (Should be users, not the web server issuing the request)

    //Set referrer (if applicable)

    $t->doTrackPageView('Image viewed');

    $im = imagecreatefrompng("stats.png");

    //For transparency (Alpha blending)
    imagealphablending($im, true);
    imagesavealpha($im, true);

    //Set header
    header('Content-Type: image/png');
    //Output image
    //Unload image

You can set many more visitor details, refer to the reference.

Create a .htaccess file in the same folder. We will use this to rewrite the URL so that we can still use a .png extension for the file. When stats_t.png is called, Apache will instead load stats_t.php , which will run the tracking code.

RewriteEngine On
RewriteRule stats_t.png stats_t.php

Your folder structure should now look like this:

Verify that your image is displayed properly in a web browser by navigating to stats_t.png

Verify that Piwik recorded the visit correctly. If it did not, make sure you have entered $token_auth and $idSite correctly.

Step 4 – Display your new tracking image anywhere

Now you can include your image anywhere, like this:

<img src="" alt="thumbs up" />

If you would like more information please see the official documentation of the Tracking API.

Let me know if this helped you out or if you have any suggestions or improvements!

Update: Now includes referrer tracking. If the image is used on a page, you will see what page it is used on. (See line 19 and 20 of stats_t.php)

15 web design resources that will save you time and improve your designs!


I have been doing quite a lot of creative work recently in the domain of web design (get it, “domain”, har har!) , and I’d be happy to share some of the great web sites and applications that have helped me make better and cleaner design and code jobs. I have divided the sites into six categories, so take your pick and dig in!

If you have any suggestions of your own, I’d be happy to hear them, leave a comment and be heard!

Cliparts and photos

image – Royalty free photography, or stock.xchng, is the little brother of  iStockphoto. They offer royalty-free photography for non-commercial use, and an option to contact the authors for use in commercial application using a very relaxed license. My experience with the people there has been great as a whole, highly recommended and great array of photographs, but also clip art.

image – public domain clip art offers public-domain clip art uploaded by users. Great site for any smaller images that you might need, such as bullets and icons.



Common font list
When designing a page, you need to make sure you use a font that is visible to and looks visually similar for every viewer, and degrade gracefully in the cases where the font is not present on the viewers computer. This useful webpage displays common font families that work over a wide array of browsers and operating systems.



BrowserShots has lost its glory days as the go-to site for making sure your web pages look equal across all browsers due to its increasingly long rendering waiting time and restrictions, and with IETester mentioned below, you can verify that your page runs properly on all major browsers.

But BrowserShots has introduced a fantastic gallery of web designs, and this is a place where you can find great inspiration.


ColorSchemer gallery and ColourLovers palette gallery
Finding the correct colors for your site can be a surprisingly difficult challenge, but when browsing these galleries, this becomes a fun experience. The idea is that you pick a scheme, which contains roughly 3-8 colors, and then try to base your design around these. If you try it, you’ll find a surprisingly clean and beautiful site looking back at you when you are finished. Using schemes with multiple variation of the same color (like this one) has worked the best for me.


Web Design From Scratch
A great resource for articles about the philosophy behind, and practical application to modern web design.



Sizer is a small application which allows you to easily resize your browser (or really, any) window to see your web pages (hopefully) degrade in a graceful manner. Simple and easy, yet invaluable.


Firebug (Firefox add-on)
Firebug is a great web developer tool built as a Firefox add-on. I have barely scraped the surface of this great tool, but it has been very helpful so far.


Your web design and CSS looks great in the latest versions of Firefox, Chrome, Opera and IE? You’re not done yet! Unfortunately, a large portion of people still use Internet Explorer 7 and 6 (*shudders*) and this tool will help you make sure your design stays true to its form. (although it probably won’t until you spend an hour trying to figure out why IE6/7 doesn’t handle inline block  properly, which brings us to…)

Fixes and hacks for common problems

This might seem like an odd choice at first, but if you’ve ever had a problem, googling will almost always lead to an answer. The great thing about the internet is that chances are great that somewhere, someone has had your exact problem and either asked about it in a forum or given a solution in a blog post, which will usually lead you closer to an answer.


It is fairly common knowledge that Internet Explorer 6 and below does not handle the alpha channel (transparency) for PNG images properly and displays the whole transparent area as a gray box. Resorting to GIF is possible for single-colored background, but for patterned backgrounds your only choice is PNG and this fix (Which is mostly done in CSS) will take care of that.

A quick note: I have noticed that the JavaScript used for tiling images in “IE PNG Fix”, which is called “iepngfix_tilebg.js” seems to break the dropdown functionality of Superfish, which I mentioned earlier. I have been looking at the problem, but haven’t been able to identify the culprit, although I suspect it is related to the way the JS places the image. Unless you absolutely need tiling support, it’s best not to use the JS code, so beware!

CSS Sticky Footer
Making a footer that always stays at the bottom of the page, moves with JavaScript and  works over all major browsers is a surprisingly difficult task, but CSS Sticky Footer takes care of it. It requires you to import a fairly large CSS file, but it shouldn’t break your layout too much, aside from a margin that needs fixing here and there.


CodeIgniter PHP Framework
CodeIgniter is a great framework for easily making web applications in PHP. The features I have enjoyed so far is the fantastic database handling using Active Record, the interesting Model-View-Controller approach (which was new to me) and the great performance I get from my applications. If you want to know what the hype is about, check out this video tutorial entitled “Create a blog in 20 minutes”!


Suckerfish JavaScript/CSS menu system
Another thing that seems like there should be a myriad of online, but is surprisingly difficult to find is a menu that works over all browsers, is completely free, simple to use and can be used in commercial applications. Look no further, Suckerfish is what you have been waiting for! And it degrades nicely to CSS-only under environments without JS too!

When I grow up, I want to be a search engine!



To the outside world, the Majestic12 website doesn’t look like much – it hardly even resembles a search engine.  But behind that plain-looking facade, Majestic12 is a living, breathing organism with thousands of participating computers who crawl the web for content and links . Majestic12 users donate their bandwidth to the project, and I’m trying to do my part. The actual search engine of the project is still after almost four years of crawling pretty much useless, and any of the larger search engines do a far better job, but the concept is intriguing and the thought is good. Another interesting idea is that you can create your own search algorithm, providing you are handy enough! All that is needed is to register on the search engine subsite and start tinkering with the priorities that you feel are important in search results.


I’ve got the power! Now if I just edit a random memory location anndd…

Of course, with putting the trust in the end users comes great responsibility – a user might have had his DNS records hijacked, rerouting sites incorrectly and possibly lowering the ranking of benevolent sites while improving that of malicious ones – or he might be a ill-natured hacker himself, possibly trying to employ SEO for his own or a contractors site,  requiring double- and triple-checking by independent other users of the project, as suggested in this forum post, which increases the load on web servers as each page has to be checked multiple times to ensure correctness. This hasn’t seemed to be a problem thus far, but as the search engine grows I hope that the programmers behind this extremely ambitious project are prepared for counter-measures. All I can do for now is to urge you to start your own node and help with this project. The crawling software runs under Windows, OSX and Linux.

Majestic12 is a great alternative to other causes like SETI@Home and it might very well be the future of search engines.

Majestic 12? That sounds familiar!
You weren’t the only one to think that! Majestic 12 is one of the most popular conspiracy theories of all times and is thought to be a secret committee consisting of scientists and government officials gathered by president Truman after the supposed UFO Crash in Roswell, New Mexico in 1947. There is a huge amount of information on the topic, and I haven’t even had time to skim the surface, but it seems like a fascinating read.

In other news…

The b(a/ea)stard in action

Ever since Mattias showed me Bastard Tetris, he has (possibly) inadvertently killed a small part of my soul. This seemingly innocent Tetris clone uses a custom-built algorithm that instead of randomizing the tetrominos you get, tries to give you the worst piece computationally possible. It even mocks you by showing which piece it will absolutely not give you under any circumstance. Oh the pain. My current record after a few infuriating games is 250 points, which translates to a measly five cleared lines. This game should be available to all *NIX and Linux distributions, and is called bastet in packet managers around the planet. For anyone else who wishes to play this I found a clone made in flash, although the algorithm seemed nicer as I managed to clear six lines on my first attempt.