&link= not redirecting (1.1.1 upgrade)


#1

Hi fellow Piwik users,

Until my upgrade to Piwik 1.1.1 (from 1.0) I was using link-tracking to track the effectiveness of my newsletters and redirects.
I would typically sent links like

http://piwik.fwrite.org/piwik.php?idsite=1&rec=1&url=http%3A%2F%2Flibanonxp.nl%2F&link=http%3A%2F%2Fbuddy.libanonxp.nl%2F

This independence from Javascript was very practical as most of the time I’m referring people to websites that are not in my own administration.

In Piwik 1.1.1 the links don’t redirect anymore, but only give blank 1×1 GIF.
Is there a way to get my tracking back on track?

Thanks in advance,

Adriaan

Edit: pressed ‘save changes’ by accident. Finished my message!


#2

I just found the debug-mode.
As confirmed by previous tests (not mentioned in my first post) the visits are properly recorded tough not redirected.

With the debug-mode on, it’s visible that Piwik properly understands the request.

Here is my sample request:

http://piwik.fwrite.org/piwik.php?idsite=1&rec=1&redirect=1&action_name=Test&url=http%3A%2F%2Flibanonxp.nl%2F&link=http%3A%2F%2Fgoogle.nl%2F

or, split up:

http://piwik.fwrite.org/piwik.php
  ?idsite=1
  &rec=1
  &redirect=1
  &action_name=Test
  &url=http%3A%2F%2Flibanonxp.nl%2F
  &link=http%3A%2F%2Fgoogle.nl%2F

The output can be found on this page: http://pastehtml.com/view/1cqykca.html.


(vipsoft) #3

You can write a proxy, e.g.,


<?php
if($_SERVER['REQUEST_METHOD'] == 'POST' || !empty($_SERVER['QUERY_STRING'])) {
	ob_start();
	include '/path-to-/piwik.php';
	ob_get_clean(); // this discards the HTTP response and image returned

	// do your redirect here
	header("Location: " . $YOUR_URL_HERE );

	exit;
}

p.s. the redirect parameter was deprecated and undocumented, and finally, removed in 1.1.


#4

My redirect.php (in the same folder as piwik.php):


<?php
/*
 * Fall-back for the removed redirect function of Piwik.
 * See http://forum.piwik.org/read.php?2,71128,71154 .
 */

if(!empty($_SERVER['QUERY_STRING']) AND (!empty($_REQUEST['link']) OR !empty($_REQUEST['download']))) {
  ob_start();
  require './piwik.php';
  ob_get_clean(); // Discard the HTTP response and image returned

  // Determine new link
  $sURL = (!empty($_REQUEST['link']) ? $_REQUEST['link'] : $_REQUEST['download']);

  // Redirect
  header('HTTP/1.1 303 See Other');
  header('Content-Type: text/html; charset=UTF-8');
  header('Location: '.$sURL);
	
  echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'.PHP_EOL.
  '<html><head><title>Redirect</title></head><body>'.PHP_EOL.
  '<p>See <a href="'.htmlentities($sURL).'">'.htmlentities($sURL).'</a>.</p>'.PHP_EOL.
  '</body></html>';

  exit(0);
}else{
  header('HTTP/1.1 500 Internal Server Error');
	header('Content-Type: text/html; charset=UTF-8');
  echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'.PHP_EOL.
       '<html><head><title>Redirect error</title></head><body>'.PHP_EOL.
  '<p>The server couldn\'t understand your request.</p>'.PHP_EOL.
  '</body></html>';

  exit(1);
}

The cross-site referencing problem (that was probably the reason for deletion) stays in tact this way! More checks (to prevent this) could be added easily.