Sorry if this was answered somewhere else but I’ve searched and can’t seem to find the answer. I use a small php script to handle all the affiliate links on a website, this is the code I use:
Thanks Matt, I checked it out and after lots of trial and error I got it to work. I thought I would share the code as some of it was hard to find:
Creat a file named outbound.php and place this code in it:
<?php
// -- Start Piwik Tracking --
require_once "outbound-tracking.php"; /* The tracking file you upload - I renamed mine to something unique */
PiwikTracker::$URL = 'http://www.your-site.com/mystats/'; /* The URL specified in your site tracking code */
$piwikTracker = new PiwikTracker( $idSite = 1 ); /* The Site ID also found in your tracking code */
$piwikTracker->setTokenAuth( 'your-auth-code-here' ); /* The token_auth found on the API page of your CP - required to get users IP */
$piwikTracker->setVisitorId($piwikTracker->getVisitorId()); /* You need to add this so the user id isn't lost and thier tracking starts over */
$piwikTracker->setIp( $_SERVER['REMOTE_ADDR'] ); /* Log visitor IP if you like */
$piwikTracker->setUrl($url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); /* Set the current URL */
$piwikTracker->doTrackPageView( $_GET['id'] ); /* Log the Visit */
// -- End Piwik Tracking --
?>
<?php
$id = $_GET['id'];
$redirect = array(
'name1'=>'http://www.affiliatelink1.com/',
'name2'=>'http://www.affiliatelink2.com/',
);
header('HTTP/1.1 301 Moved Permanently');
header('Location:'.$redirect[$id]);
header('Connection: close');
exit();
?>
The file is called like so : outbound.php?id=name1
Create a new Goal in your control panel triggered by “Visit a given URL” where the “contains” value is : outbound.php
That’s it, you’re redirect will show inline with the rest of thier visit. There may be an easier way but this is what worked for me