Unique problem with using an app and tracking the correct setVisitorId (PHP Server side)

Hello,

As of yesterday I’ve been able to install piwik and get some great results. Thanks for the top notch app.

However, I’m struggle to accomplish a couple of things.

Here is the scenario.

I’ve been able to embed the code in to our mobile app, which was relatively easy. And like many apps, it’s basically a front end to a website. I am only able to use the php server side tracking to do all this, so no javascript. This is because out app specifically uses XML to create it’s conent, but I can export the XML using PHP, thus the server side inclusion and use.

I can get piwik to navigate through and track the various XML files “pages” without issues and have them register fine as stats and properly visitors and it shows the nagivation path etc.

However, the problem I’m having is when a link in the app goes to an internal webview webrowser (in Android, Windows Mob, or iOS).
Piwik behaves a little strange and seems to change the VisitorId during the change over, and thus wrecks the tracking ability of the “user navigation”.

For instance, in the live User Logs, I get a navigation like this:

User phone: IP: 123.123.123.123
VisitorID: abcdabcdabcdabcd1
HOME->Page 1->Page 2

User phone: IP: 123.123.123.123
VisitorID: abcdabcdabcdabcd2
Web Browser 3

Instead of a consistent path that I would like, like this:

User phone: IP: 123.123.123.123
VisitorID: abcdabcdabcdabcd1
HOME->Page 1->Page 2->Web Browser 3

I’ve tried passing the Visitor ID with code like this: link.php?vid=’ . $t->getVisitorId() . '
and trying to pick it up at the other end, which it’s recieving via a $_GET
and trying to set it like this: $t->setVisitorId($vid);

However, it’s like it’s not setting it in the final instance and is just assigning a brand new visitor Id.
At what point do I need to set the visitor id, so that it’s sent back to the sever for recording?

Example of some of what’s on the last page: “Web Browser 3” for the example shown.

// – Piwik Tracking API init –
require_once “PiwikTracker.php”;
PiwikTracker::$URL = ‘http://www.SERVER/piwik/’;

$IDSITE = 2; // 2 is the main.

if( isset($_POST[‘vid’]) )
{
$vid = addslashes($_POST[‘vid’]);
}
else
{
if( isset($_GET[‘vid’]) )
{
$vid = addslashes($_GET[‘vid’]);
}
}

$t = new PiwikTracker( $idSite = 2, ‘http://www.SERVER/piwik/’);

// Optional function calls
$t->setBrowserLanguage(‘en’);

if(isset($_SERVER[‘HTTP_REFERER’]))
$t->setUrl($_SERVER[‘HTTP_REFERER’]);

$token_auth = “XXXXXXXXXXXXXXXXXXXXXXXXXXXX”; // good
$t->setTokenAuth( $token_auth ); // good
$t->setIp( $_SERVER[‘REMOTE_ADDR’]); // good
$t->setUrl( $url = ‘http://SERVER/lastpage.php’ );
$t->doTrackPageView(‘Mobile Recently Played’);
$t->setVisitorId($vid);

Is this common or am I going about this in the wrong way?
Many thanks.
-Steve

Solution:
Ok… here’s an update for you all.

What seems to be key is the order in which the code is set.

$token_auth = “XXXXXXXXXXXXXXXXXXXXXXXXXXXX”; // good
$t->setTokenAuth( $token_auth ); // good
$t->setVisitorId($vid);

Seems the setVisitorId needs to be straight after the token - before anything else.