I am tracking a goal (actually, just the page view) in a PHP redirect (HTTP 302) script using the PHP API with the following code:
PiwikTracker::$URL = 'http://'.$_SERVER['HTTP_HOST'].'/piwik/';
$piwikTracker = new PiwikTracker(1);
$piwikTracker->setUrl($_SERVER['REQUEST_URI']);
$piwikTracker->doTrackPageView('<Page Title>');
This works fine so far. The Problem now is, that the users leave site for one page view before calling this PHP redirect page, like in the following diagram:
That means, that all the session information (referer, viewing time, …) from the piwik tracking is lost, and the users are recorded as a new visit coming from ‘External Page’. Is there any way to pass or re-attach the previous visiting session in the PHP redirect page?
Unfortunately, this doesn’t seem to work.
If I set the request URL of the last accessed Piwik-enabled page in the PHP redirect script with setUrlReferrer(), the page views (and its goals) of the redirect script are recorded as direct entries.
Like this should be correct, right?
Custom Page Z, Piwik-enabled Site:
/* add this site's URI as p_ref URL parameter to external page */
$href_link = url_of(External Page View).'&p_ref='.urlencode($_SERVER['SCRIPT_URI']);
External page will forward p_ref URL parameter to PHP redirect page.