Best Way to Redirect via Piwik

Hi there,

I’m new to piwik but I know how to program PHP and JS.

I would like to know the best way to achieve the following:
There’s a website A where I place some of my advertisements on. Each advertisement has its own destination URL, which can be set by me. Different advertisements have different websites as their destinations - B, C and D. Unfortunately I’m only allowed to install the piwik JS on website B, but I also want to track traffic that’s going to C and D. Therefore I’d like to redirect that traffic from the advertisements via the Server I installed piwik on to C and D.

I thought about writing the redirecting in PHP and use the tracking API, but it seems as if this does not allow me to set a piwik Cookie (which I definetly need for later goal/conversion tracking). So how to achieve this?

I hope that I’ve made my case clear enough… if not, please ask.

I’m really looking forward to read your suggestions!

noisyrabbit

Might the following approach be a solution to redirect via Piwik, i.e. set a cookie and still track as much as possible?

Example URL:
piwik.php?piwik.php?idsite=1&rec=1&redirect=www.piwik.org

The following code is simplified:

class Piwik_Redirect extends Piwik_Plugin
{
    public function getListHooksRegistered()
    {
        return array(
            'Tracker.Action.record' => 'redirectVisitor',
        );
    }

    function redirectVisitor($notification)
    {
        header('Location: '.$_GET['redirect']);
    }
}

I’m looking forward to read your comments.

This code is insecure.
It would allow uncontrolled redirects.
See Owasp A10 (Top 10 2013)