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

  • The powerless God

    Bas
    Hi Chris, Well... I'm not saying that there is no free will in the afterlife. But life as we know is ...

    Read more...

     
  • The powerless God

    Chris Donges
    How do you see the afterlife if there is no free will? If there can be an afterlife with no free will ...

    Read more...

     
  • The powerless God

    Bas
    Hi Chris, I'm curious where you are heading with your questions :-) I'm not that interested in heaven ...

    Read more...

     
  • The powerless God

    Chris Donges
    I know you said free will may not be the correct answer but I asked so I could ask you this follow ...

    Read more...

     
  • The powerless God

    Bas
    Hi Chris! No, I don't think so. May I ask you why you asked me this? I've re-read my blogpost and ...

    Read more...