Joomla RSS Feed stats in Piwik

As you may know or have noticed I don't use Google Analytics. Instead I use an open source variant called Piwik.

I really love Piwik, but always had one wish: I want to see the visitors that read this blog through feeds. After some time of trying and searching I decided to write my own Joomla plugin that uses the Piwik Tracking API. Here are some code snippets to show you how it's done. If you want the plugin, download it here:

The Joomla plugin isn't very complicated. Without the standard plugin code, the actual Piwik Tracking code looks like this. I used the onAfterDispatch event to track this request with Piwik.

$mainframe = JFactory::getApplication();

// Only modify site pages that are not admin, install, etc.
if ( $mainframe->isSite() )
{
    // Only add stats for feed requests
    if ( $_REQUEST['format'] == 'feed' )
    {
        // Require the Piwik integration file
        require_once 'PiwikTracker.php';

        // Create tracker
        $piwikTracker = new PiwikTracker( $idSite = $this->params->get('siteid'), $apiUrl = $this->params->get('piwikuri'));
        $piwikTracker->setUrl( $url = $_SERVER['REQUEST_URI'] );
        // The auth token is required for overriding the server data with the original user data (such as IP-adress)
        $piwikTracker->setTokenAuth( $this->params->get('piwikauthtoken') );

        // Sends Tracker request via http
        $piwikTracker->doTrackPageView($this->params->get('pagetitle'));
    }
}

This content has been locked. You can no longer post any comment.

Share this post
FaceBook  Twitter  

Archives

Latest comments